Spaces:
Running
Running
import gradio as gr | |
from gradio_client import Client, handle_file | |
import requests | |
from PIL import Image | |
import io | |
def predict(image, question, seed, top_p, temperature): | |
# Inicializa o cliente do Gradio | |
client = Client("deepseek-ai/Janus-Pro-7B") | |
# Prepara a imagem para envio | |
if image.startswith('http'): | |
response = requests.get(image) | |
img_path = handle_file(io.BytesIO(response.content)) | |
else: | |
img_path = handle_file(image) | |
# Faz a predição | |
result = client.predict( | |
image=img_path, | |
question=question, | |
seed=seed, | |
top_p=top_p, | |
temperature=temperature, | |
api_name="/multimodal_understanding" | |
) | |
return result | |
# Componentes da interface | |
image_input = gr.Image(label="Upload Image", type="filepath") | |
question_input = gr.Textbox(label="Question", placeholder="Ask something about the image...") | |
seed_slider = gr.Slider(0, 100, value=42, label="Seed") | |
top_p_slider = gr.Slider(0, 1, value=0.95, label="Top-p") | |
temp_slider = gr.Slider(0, 1, value=0.1, label="Temperature") | |
# Cria a interface | |
demo = gr.Interface( | |
fn=predict, | |
inputs=[ | |
image_input, | |
question_input, | |
seed_slider, | |
top_p_slider, | |
temp_slider | |
], | |
outputs=gr.Textbox(label="Answer"), | |
title="Janus-Pro-7B Multimodal Demo", | |
description="Ask questions about images using the Janus-Pro-7B model", | |
examples=[ | |
["https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png", "What's in this image?", 42, 0.95, 0.1] | |
] | |
) | |
if __name__ == "__main__": | |
demo.launch() |