Spaces:
Running
Running
File size: 1,634 Bytes
503de01 |
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
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() |