Merge pull request #32 from djwesty/vutukuri15/30

Fixed welcome screen issue # 30
This commit is contained in:
Vutukuri15 2025-02-24 00:09:29 -08:00 committed by GitHub
commit ce222a0ed3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 1121 additions and 899 deletions

View File

@ -1,3 +1,4 @@
API_KEY=Put Open AI key here
GPT_MODEL=gpt-4o-mini
#GPT_MODEL=gpt-4-turbo # More expensive model, use sparingly
EXPO_PUBLIC_API_URL=https://api.openai.com/v1/chat/completions
EXPO_PUBLIC_API_KEY=put-open-ai-key-here
EXPO_PUBLIC_MODEL_NAME=gpt-4o-mini
#EXPO_PUBLIC_MODEL_NAME=gpt-4-turbo # More expensive model, use sparingly

View File

@ -18,14 +18,15 @@ This is an [Expo](https://expo.dev) project created with [`create-expo-app`](htt
To set up your environment variables:
1. Copy the example environment variable file to create your own .env file:
1. Copy the example environment variable file to create your own `.env` file:
```bash
cp .env.example .env
```
2. Open the .env file and add your OpenAI API key:
2. Open the `.env` file and add your OpenAI API key:
API_KEY=your_openai_api_key_here
MODEL_NAME=your_model_name
`EXPO_PUBLIC_API_KEY=put-open-ai-key-here`
3. Save the .env file.

View File

@ -1,15 +0,0 @@
module.exports = {
presets: ["babel-preset-expo", "@babel/preset-typescript"],
plugins: [
[
"module:react-native-dotenv",
{
moduleName: "@env",
path: ".env",
safe: true,
allowUndefined: false,
},
],
"react-native-reanimated/plugin",
],
};

View File

@ -8,7 +8,6 @@ import {
ScrollView,
} from "react-native";
import * as ImagePicker from "expo-image-picker";
import { API_KEY, MODEL_NAME } from "@env";
const ChipDetection = ({ updateChipCount }) => {
const [imageUri, setImageUri] = useState(null);
@ -57,40 +56,37 @@ const ChipDetection = ({ updateChipCount }) => {
setError(null);
try {
const response = await fetch(
"https://api.openai.com/v1/chat/completions",
{
method: "POST",
headers: {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: MODEL_NAME,
messages: [
{
role: "system",
content:
"Identify and count poker chips by color. Return only the count for each color in JSON format.",
},
{
role: "user",
content: [
{
type: "text",
text: "How many poker chips are there for each color? Return structured JSON.",
},
{
type: "image_url",
image_url: { url: `data:image/png;base64,${base64Image}` },
},
],
},
],
max_tokens: 1000,
}),
}
);
const response = await fetch(process.env.EXPO_PUBLIC_API_URL, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.EXPO_PUBLIC_API_KEY}`, // Use environment variable for API key
"Content-Type": "application/json",
},
body: JSON.stringify({
model: process.env.EXPO_PUBLIC_MODEL_NAME, // Use environment variable for model name
messages: [
{
role: "system",
content:
"Identify and count poker chips by color. Return only the count for each color in JSON format.",
},
{
role: "user",
content: [
{
type: "text",
text: "How many poker chips are there for each color? Return structured JSON.",
},
{
type: "image_url",
image_url: { url: `data:image/png;base64,${base64Image}` },
},
],
},
],
max_tokens: 1000,
}),
});
const result = await response.json();
@ -103,12 +99,11 @@ const ChipDetection = ({ updateChipCount }) => {
const parsedData = JSON.parse(cleanJSON);
// Filter out colors with a count of 0
const filteredData = Object.fromEntries(
Object.entries(parsedData).filter(([_, count]) => count > 0)
);
setLastDetectedChips(filteredData); // Store detected chip counts
setLastDetectedChips(filteredData);
updateChipCount(filteredData);
} catch (error) {
setError("Failed to analyze the image.");

1834
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -14,57 +14,57 @@
"jest": {
"preset": "jest-expo"
},
"engines": {
"node": ">=22.0.0 <23.0.0"
},
"dependencies": {
"@babel/preset-typescript": "^7.26.0",
"@expo/vector-icons": "^14.0.2",
"@react-navigation/bottom-tabs": "^7.2.0",
"@react-navigation/native": "^7.0.14",
"expo": "~52.0.31",
"expo-blur": "~14.0.3",
"expo-constants": "~17.0.5",
"expo-file-system": "~18.0.11",
"expo-font": "~13.0.3",
"expo-haptics": "~14.0.1",
"expo-image-picker": "~16.0.6",
"expo-linking": "~7.0.5",
"expo-router": "~4.0.17",
"expo-splash-screen": "~0.29.21",
"expo-status-bar": "~2.0.1",
"expo-symbols": "~0.2.2",
"expo-system-ui": "~4.0.8",
"expo-web-browser": "~14.0.2",
"metro-react-native-babel-preset": "^0.77.0",
"@expo/vector-icons": "14.0.4",
"@react-navigation/bottom-tabs": "7.2.0",
"@react-navigation/native": "7.0.14",
"expo": "52.0.37",
"expo-blur": "14.0.3",
"expo-constants": "17.0.7",
"expo-file-system": "18.0.11",
"expo-font": "13.0.4",
"expo-haptics": "14.0.1",
"expo-image-picker": "16.0.6",
"expo-linking": "7.0.5",
"expo-router": "4.0.17",
"expo-splash-screen": "0.29.22",
"expo-status-bar": "2.0.1",
"expo-symbols": "0.2.2",
"expo-system-ui": "4.0.8",
"expo-web-browser": "14.0.2",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-native": "^0.76.7",
"react-native-dotenv": "^3.4.11",
"react-native-gesture-handler": "~2.20.2",
"react-native-reanimated": "~3.16.1",
"react-native": "0.76.7",
"react-native-gesture-handler": "2.20.2",
"react-native-reanimated": "3.16.7",
"react-native-safe-area-context": "4.12.0",
"react-native-screens": "~4.4.0",
"react-native-web": "~0.19.13",
"react-native-screens": "4.4.0",
"react-native-web": "0.19.13",
"react-native-webview": "13.12.5"
},
"devDependencies": {
"@babel/core": "^7.26.9",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-native": "^5.4.3",
"@testing-library/react": "^16.2.0",
"@testing-library/react-native": "^13.0.1",
"@types/jest": "^29.5.12",
"@types/react": "~18.3.12",
"@types/react-test-renderer": "^18.3.0",
"eslint": "^9.20.0",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-react": "^7.37.4",
"eslint-plugin-react-native": "^5.0.0",
"jest": "^29.7.0",
"jest-expo": "~52.0.3",
"jest-fetch-mock": "^3.0.3",
"prettier": "^3.4.2",
"@babel/core": "7.26.9",
"@testing-library/dom": "10.4.0",
"@testing-library/jest-native": "5.4.3",
"@testing-library/react": "16.2.0",
"@testing-library/react-native": "13.0.1",
"@types/jest": "29.5.14",
"@types/react": "18.3.12",
"@types/react-test-renderer": "18.3.0",
"eslint": "9.21.0",
"eslint-config-prettier": "10.0.1",
"eslint-plugin-prettier": "5.2.3",
"eslint-plugin-react": "7.37.4",
"eslint-plugin-react-native": "5.0.0",
"jest": "29.7.0",
"jest-expo": "52.0.5",
"jest-fetch-mock": "3.0.3",
"prettier": "3.5.2",
"react-test-renderer": "18.3.1",
"typescript": "^5.7.3"
"typescript": "5.7.3"
},
"private": true
}