Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,15 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
API_URL = "https://
|
| 6 |
|
| 7 |
def chat(image, text):
|
| 8 |
-
"""
|
| 9 |
if image is None:
|
| 10 |
-
return "
|
| 11 |
|
| 12 |
-
#
|
| 13 |
image.save("temp.jpg")
|
| 14 |
|
| 15 |
files = {"image": open("temp.jpg", "rb")}
|
|
@@ -17,18 +17,18 @@ def chat(image, text):
|
|
| 17 |
|
| 18 |
try:
|
| 19 |
response = requests.post(API_URL, files=files, data=data)
|
| 20 |
-
return response.json().get("response", "
|
| 21 |
except Exception as e:
|
| 22 |
-
return f"
|
| 23 |
|
| 24 |
-
#
|
| 25 |
iface = gr.Interface(
|
| 26 |
fn=chat,
|
| 27 |
-
inputs=[gr.Image(type="pil"), gr.Textbox(lines=2, placeholder="
|
| 28 |
outputs=gr.Textbox(),
|
| 29 |
title="LLaVA Visual Chatbot",
|
| 30 |
-
description="
|
| 31 |
)
|
| 32 |
|
| 33 |
-
#
|
| 34 |
iface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
|
| 4 |
+
# Your ngrok URL (ensure it is correct)
|
| 5 |
+
API_URL = "https://0e8b-169-233-7-2.ngrok-free.app/predict/"
|
| 6 |
|
| 7 |
def chat(image, text):
|
| 8 |
+
"""Call the local LLaVA server API"""
|
| 9 |
if image is None:
|
| 10 |
+
return "Please upload an image."
|
| 11 |
|
| 12 |
+
# Save the image as a temporary file
|
| 13 |
image.save("temp.jpg")
|
| 14 |
|
| 15 |
files = {"image": open("temp.jpg", "rb")}
|
|
|
|
| 17 |
|
| 18 |
try:
|
| 19 |
response = requests.post(API_URL, files=files, data=data)
|
| 20 |
+
return response.json().get("response", "Error: Unable to parse response.")
|
| 21 |
except Exception as e:
|
| 22 |
+
return f"Request failed: {str(e)}"
|
| 23 |
|
| 24 |
+
# Create Gradio interface
|
| 25 |
iface = gr.Interface(
|
| 26 |
fn=chat,
|
| 27 |
+
inputs=[gr.Image(type="pil"), gr.Textbox(lines=2, placeholder="Enter your question")],
|
| 28 |
outputs=gr.Textbox(),
|
| 29 |
title="LLaVA Visual Chatbot",
|
| 30 |
+
description="Upload an image and enter a question. LLaVA will provide an answer.",
|
| 31 |
)
|
| 32 |
|
| 33 |
+
# Launch Gradio
|
| 34 |
iface.launch(server_name="0.0.0.0", server_port=7860)
|