Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| # Your ngrok URL (ensure it is correct) | |
| API_URL = "https://36b83bc0ff0b.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) | |