Spaces:
Sleeping
Sleeping
import gradio as gr | |
import requests | |
# Your ngrok URL (ensure it is correct) | |
API_URL = "https://e961-169-233-7-2.ngrok-free.app/predict/" | |
def chat(image, text): | |
"""Call the local LLaVA server API""" | |
if image is None: | |
return "Please upload an image." | |
# Save the image as a temporary file | |
image.save("temp.jpg") | |
files = {"image": open("temp.jpg", "rb")} | |
data = {"text": text} | |
try: | |
response = requests.post(API_URL, files=files, data=data) | |
return response.json().get("response", "Error: Unable to parse response.") | |
except Exception as e: | |
return f"Request failed: {str(e)}" | |
# Create Gradio interface | |
iface = gr.Interface( | |
fn=chat, | |
inputs=[gr.Image(type="pil"), gr.Textbox(lines=2, placeholder="Enter your question")], | |
outputs=gr.Textbox(), | |
title="LLaVA Visual Chatbot", | |
description="Upload an image and enter a question. LLaVA will provide an answer.", | |
) | |
# Launch Gradio | |
iface.launch(server_name="0.0.0.0", server_port=7860) | |