Fixed welcome screen issue # 30 #32

Merged
Vutukuri15 merged 3 commits from vutukuri15/30 into main 2025-02-24 00:09:29 -08:00
6 changed files with 1121 additions and 899 deletions

View File

@ -1,3 +1,4 @@
API_KEY=Put Open AI key here EXPO_PUBLIC_API_URL=https://api.openai.com/v1/chat/completions
GPT_MODEL=gpt-4o-mini EXPO_PUBLIC_API_KEY=put-open-ai-key-here
#GPT_MODEL=gpt-4-turbo # More expensive model, use sparingly 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: 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 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 `EXPO_PUBLIC_API_KEY=put-open-ai-key-here`
MODEL_NAME=your_model_name
3. Save the .env file. 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, ScrollView,
} from "react-native"; } from "react-native";
import * as ImagePicker from "expo-image-picker"; import * as ImagePicker from "expo-image-picker";
import { API_KEY, MODEL_NAME } from "@env";
const ChipDetection = ({ updateChipCount }) => { const ChipDetection = ({ updateChipCount }) => {
const [imageUri, setImageUri] = useState(null); const [imageUri, setImageUri] = useState(null);
@ -57,16 +56,14 @@ const ChipDetection = ({ updateChipCount }) => {
setError(null); setError(null);
try { try {
const response = await fetch( const response = await fetch(process.env.EXPO_PUBLIC_API_URL, {
"https://api.openai.com/v1/chat/completions",
{
method: "POST", method: "POST",
headers: { headers: {
Authorization: `Bearer ${API_KEY}`, Authorization: `Bearer ${process.env.EXPO_PUBLIC_API_KEY}`, // Use environment variable for API key
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
model: MODEL_NAME, model: process.env.EXPO_PUBLIC_MODEL_NAME, // Use environment variable for model name
messages: [ messages: [
{ {
role: "system", role: "system",
@ -89,8 +86,7 @@ const ChipDetection = ({ updateChipCount }) => {
], ],
max_tokens: 1000, max_tokens: 1000,
}), }),
} });
);
const result = await response.json(); const result = await response.json();
@ -103,12 +99,11 @@ const ChipDetection = ({ updateChipCount }) => {
const parsedData = JSON.parse(cleanJSON); const parsedData = JSON.parse(cleanJSON);
// Filter out colors with a count of 0
const filteredData = Object.fromEntries( const filteredData = Object.fromEntries(
Object.entries(parsedData).filter(([_, count]) => count > 0) Object.entries(parsedData).filter(([_, count]) => count > 0)
); );
setLastDetectedChips(filteredData); // Store detected chip counts setLastDetectedChips(filteredData);
updateChipCount(filteredData); updateChipCount(filteredData);
} catch (error) { } catch (error) {
setError("Failed to analyze the image."); setError("Failed to analyze the image.");

1832
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

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