Update app.py
Browse files
app.py
CHANGED
@@ -5,11 +5,12 @@ from openai import OpenAI
|
|
5 |
import os
|
6 |
import base64
|
7 |
import io
|
8 |
-
import glob
|
9 |
|
|
|
10 |
client = OpenAI(
|
11 |
-
api_key=os.
|
12 |
-
base_url=os.
|
|
|
13 |
|
14 |
MODELS = [
|
15 |
"google/gemini-flash-1.5",
|
@@ -46,14 +47,27 @@ def analyze_label(image, model):
|
|
46 |
except Exception as e:
|
47 |
return f"Error analyzing image: {str(e)}"
|
48 |
|
49 |
-
#
|
50 |
-
example_images =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
iface = gr.Interface(
|
53 |
fn=analyze_label,
|
54 |
inputs=[
|
55 |
gr.Image(type="pil", label="Upload a picture of a product label, food item, or menu"),
|
56 |
-
gr.Dropdown(choices=MODELS, label="Select Model")
|
57 |
],
|
58 |
outputs=gr.Textbox(label="Analysis"),
|
59 |
title="🍏 Sehat GPT 🥦",
|
@@ -61,5 +75,5 @@ iface = gr.Interface(
|
|
61 |
examples=[[img, MODELS[0]] for img in example_images]
|
62 |
)
|
63 |
|
64 |
-
# For
|
65 |
-
|
|
|
5 |
import os
|
6 |
import base64
|
7 |
import io
|
|
|
8 |
|
9 |
+
# For Gradio spaces, it's better to use secrets for API keys
|
10 |
client = OpenAI(
|
11 |
+
api_key=os.environ.get('OPENAI_API_KEY'),
|
12 |
+
base_url=os.environ.get('OPENAI_API_BASE')
|
13 |
+
)
|
14 |
|
15 |
MODELS = [
|
16 |
"google/gemini-flash-1.5",
|
|
|
47 |
except Exception as e:
|
48 |
return f"Error analyzing image: {str(e)}"
|
49 |
|
50 |
+
# Define example images
|
51 |
+
example_images = [
|
52 |
+
'images (1).png',
|
53 |
+
'images (2).png',
|
54 |
+
'images (3).png',
|
55 |
+
'images (4).png',
|
56 |
+
'images (5).png',
|
57 |
+
'images (6).png',
|
58 |
+
'images (7).png',
|
59 |
+
'images (8).png',
|
60 |
+
'images (9).png',
|
61 |
+
'images (10).png',
|
62 |
+
'images (11).png',
|
63 |
+
'images (12).png'
|
64 |
+
]
|
65 |
|
66 |
iface = gr.Interface(
|
67 |
fn=analyze_label,
|
68 |
inputs=[
|
69 |
gr.Image(type="pil", label="Upload a picture of a product label, food item, or menu"),
|
70 |
+
gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[0])
|
71 |
],
|
72 |
outputs=gr.Textbox(label="Analysis"),
|
73 |
title="🍏 Sehat GPT 🥦",
|
|
|
75 |
examples=[[img, MODELS[0]] for img in example_images]
|
76 |
)
|
77 |
|
78 |
+
# For Gradio spaces, we use this to launch the interface
|
79 |
+
iface.launch()
|