Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gradio_client import Client, handle_file
|
3 |
+
import requests
|
4 |
+
from PIL import Image
|
5 |
+
import io
|
6 |
+
|
7 |
+
def predict(image, question, seed, top_p, temperature):
|
8 |
+
# Inicializa o cliente do Gradio
|
9 |
+
client = Client("deepseek-ai/Janus-Pro-7B")
|
10 |
+
|
11 |
+
# Prepara a imagem para envio
|
12 |
+
if image.startswith('http'):
|
13 |
+
response = requests.get(image)
|
14 |
+
img_path = handle_file(io.BytesIO(response.content))
|
15 |
+
else:
|
16 |
+
img_path = handle_file(image)
|
17 |
+
|
18 |
+
# Faz a predição
|
19 |
+
result = client.predict(
|
20 |
+
image=img_path,
|
21 |
+
question=question,
|
22 |
+
seed=seed,
|
23 |
+
top_p=top_p,
|
24 |
+
temperature=temperature,
|
25 |
+
api_name="/multimodal_understanding"
|
26 |
+
)
|
27 |
+
|
28 |
+
return result
|
29 |
+
|
30 |
+
# Componentes da interface
|
31 |
+
image_input = gr.Image(label="Upload Image", type="filepath")
|
32 |
+
question_input = gr.Textbox(label="Question", placeholder="Ask something about the image...")
|
33 |
+
seed_slider = gr.Slider(0, 100, value=42, label="Seed")
|
34 |
+
top_p_slider = gr.Slider(0, 1, value=0.95, label="Top-p")
|
35 |
+
temp_slider = gr.Slider(0, 1, value=0.1, label="Temperature")
|
36 |
+
|
37 |
+
# Cria a interface
|
38 |
+
demo = gr.Interface(
|
39 |
+
fn=predict,
|
40 |
+
inputs=[
|
41 |
+
image_input,
|
42 |
+
question_input,
|
43 |
+
seed_slider,
|
44 |
+
top_p_slider,
|
45 |
+
temp_slider
|
46 |
+
],
|
47 |
+
outputs=gr.Textbox(label="Answer"),
|
48 |
+
title="Janus-Pro-7B Multimodal Demo",
|
49 |
+
description="Ask questions about images using the Janus-Pro-7B model",
|
50 |
+
examples=[
|
51 |
+
["https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png", "What's in this image?", 42, 0.95, 0.1]
|
52 |
+
]
|
53 |
+
)
|
54 |
+
|
55 |
+
if __name__ == "__main__":
|
56 |
+
demo.launch()
|