File size: 1,015 Bytes
a722746
330b634
e6b49c3
ade99a4
54a90f5
a722746
 
ade99a4
a722746
ade99a4
a722746
ade99a4
a722746
 
 
 
 
 
 
ade99a4
a722746
ade99a4
a722746
ade99a4
a722746
 
ade99a4
a722746
 
ade99a4
a722746
 
ade99a4
a722746
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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)