File size: 1,110 Bytes
1c155e2
 
8fa8fc9
 
1c155e2
8fa8fc9
 
 
 
 
 
1c155e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from gradio_client import Client, handle_file
from huggingface_hub import HfApi
import time

api = HfApi()

api.restart_space(repo_id="HuggingFaceH4/idefics2-8b-playground")
api.restart_space(repo_id="HuggingFaceH4/idefics2-8b-vdpoed-playground")
while api.space_info("HuggingFaceH4/idefics2-8b-playground").runtime.stage != "RUNNING" or api.space_info("HuggingFaceH4/idefics2-8b-vdpoed-playground").runtime.stage != "RUNNING":
    time.sleep(1)

client_idefics2 = Client("HuggingFaceH4/idefics2-8b-playground")
client_idefics2_dpoed = Client("HuggingFaceH4/idefics2-8b-vdpoed-playground")


def respond(multimodal_input):
    x = {"text": multimodal_input["text"], "files": [handle_file(file) for file in multimodal_input["files"]]}
    text_1 = client_idefics2.predict(x, api_name="/predict")
    text_2 = client_idefics2_dpoed.predict(x, api_name="/predict")
    return text_1, text_2


gr.Interface(
    respond,
    inputs=[gr.MultimodalTextbox(file_types=["image"], show_label=False)],
    outputs=[gr.Textbox(label="idefics2-8b"), gr.Textbox(label="idefics2-8b-dpoed")],
).launch()