Implemented Welcome Screen Issue # 30 #31

Closed
Vutukuri15 wants to merge 2 commits from vutukuri15/25 into main
3 changed files with 1005 additions and 621 deletions

View File

@ -1,15 +1,6 @@
module.exports = { module.exports = function (api) {
presets: ["babel-preset-expo", "@babel/preset-typescript"], api.cache(true);
plugins: [ return {
[ presets: ["babel-preset-expo"],
"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,40 +56,37 @@ 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",
{ headers: {
method: "POST", Authorization: `Bearer ${process.env.EXPO_PUBLIC_API_KEY}`, // Use environment variable for API key
headers: { "Content-Type": "application/json",
Authorization: `Bearer ${API_KEY}`, },
"Content-Type": "application/json", body: JSON.stringify({
}, model: process.env.EXPO_PUBLIC_MODEL_NAME, // Use environment variable for model name
body: JSON.stringify({ messages: [
model: MODEL_NAME, {
messages: [ role: "system",
{ content:
role: "system", "Identify and count poker chips by color. Return only the count for each color in JSON format.",
content: },
"Identify and count poker chips by color. Return only the count for each color in JSON format.", {
}, role: "user",
{ content: [
role: "user", {
content: [ type: "text",
{ text: "How many poker chips are there for each color? Return structured JSON.",
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}` },
type: "image_url", },
image_url: { url: `data:image/png;base64,${base64Image}` }, ],
}, },
], ],
}, 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.");

1538
package-lock.json generated

File diff suppressed because it is too large Load Diff