Spaces:
Running
Running
kendrickfff
commited on
Commit
•
91e0dca
1
Parent(s):
f80c42d
Update app.py
Browse files
app.py
CHANGED
@@ -25,13 +25,18 @@ transform = transforms.Compose([
|
|
25 |
LABELS_URL = "https://raw.githubusercontent.com/anishathalye/imagenet-simple-labels/master/imagenet-simple-labels.json"
|
26 |
labels = json.loads(requests.get(LABELS_URL).text)
|
27 |
|
28 |
-
|
|
|
|
|
|
|
|
|
29 |
# Get a response from the language model
|
30 |
bot_response = llm.predict(message)
|
31 |
chat_history.append((message, bot_response))
|
32 |
return chat_history
|
33 |
|
34 |
-
def analyze_image(image_path
|
|
|
35 |
# Open, preprocess, and classify the image
|
36 |
image = Image.open(image_path).convert("RGB")
|
37 |
image_tensor = transform(image).unsqueeze(0)
|
@@ -58,19 +63,12 @@ with gr.Blocks() as demo:
|
|
58 |
send_btn = gr.Button("Send")
|
59 |
img_upload = gr.Image(type="filepath", label="Upload an image for analysis")
|
60 |
|
61 |
-
# Local chat history state
|
62 |
-
chat_history = []
|
63 |
-
|
64 |
# Define interactions
|
65 |
def handle_text_message(message):
|
66 |
-
|
67 |
-
chat_history = chat_with_gemini(message, chat_history)
|
68 |
-
return chat_history
|
69 |
|
70 |
def handle_image_upload(image_path):
|
71 |
-
|
72 |
-
chat_history = analyze_image(image_path, chat_history)
|
73 |
-
return chat_history
|
74 |
|
75 |
# Set up Gradio components with Enter key for sending
|
76 |
msg.submit(handle_text_message, msg, chatbot)
|
@@ -106,4 +104,5 @@ with gr.Blocks() as demo:
|
|
106 |
</style>
|
107 |
""")
|
108 |
|
109 |
-
|
|
|
|
25 |
LABELS_URL = "https://raw.githubusercontent.com/anishathalye/imagenet-simple-labels/master/imagenet-simple-labels.json"
|
26 |
labels = json.loads(requests.get(LABELS_URL).text)
|
27 |
|
28 |
+
# Global chat history variable
|
29 |
+
chat_history = []
|
30 |
+
|
31 |
+
def chat_with_gemini(message):
|
32 |
+
global chat_history
|
33 |
# Get a response from the language model
|
34 |
bot_response = llm.predict(message)
|
35 |
chat_history.append((message, bot_response))
|
36 |
return chat_history
|
37 |
|
38 |
+
def analyze_image(image_path):
|
39 |
+
global chat_history
|
40 |
# Open, preprocess, and classify the image
|
41 |
image = Image.open(image_path).convert("RGB")
|
42 |
image_tensor = transform(image).unsqueeze(0)
|
|
|
63 |
send_btn = gr.Button("Send")
|
64 |
img_upload = gr.Image(type="filepath", label="Upload an image for analysis")
|
65 |
|
|
|
|
|
|
|
66 |
# Define interactions
|
67 |
def handle_text_message(message):
|
68 |
+
return chat_with_gemini(message)
|
|
|
|
|
69 |
|
70 |
def handle_image_upload(image_path):
|
71 |
+
return analyze_image(image_path)
|
|
|
|
|
72 |
|
73 |
# Set up Gradio components with Enter key for sending
|
74 |
msg.submit(handle_text_message, msg, chatbot)
|
|
|
104 |
</style>
|
105 |
""")
|
106 |
|
107 |
+
# Launch for Hugging Face Spaces
|
108 |
+
demo.launch()
|