Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,64 +1,35 @@
|
|
1 |
-
import
|
2 |
-
from huggingface_hub import
|
|
|
3 |
|
4 |
-
|
5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
-
client = InferenceClient("HuggingFaceM4/idefics2-8b")
|
8 |
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
system_message,
|
14 |
-
max_tokens,
|
15 |
-
temperature,
|
16 |
-
top_p,
|
17 |
-
):
|
18 |
-
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
if val[1]:
|
24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
25 |
|
26 |
-
|
27 |
|
28 |
-
response = ""
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
temperature=temperature,
|
35 |
-
top_p=top_p,
|
36 |
-
):
|
37 |
-
token = message.choices[0].delta.content
|
38 |
|
39 |
-
response += token
|
40 |
-
yield response
|
41 |
|
42 |
-
|
43 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
44 |
-
"""
|
45 |
-
demo = gr.ChatInterface(
|
46 |
respond,
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
value=0.95,
|
55 |
-
step=0.05,
|
56 |
-
label="Top-p (nucleus sampling)",
|
57 |
-
),
|
58 |
-
],
|
59 |
-
multimodal=True
|
60 |
-
)
|
61 |
|
62 |
-
|
63 |
-
if __name__ == "__main__":
|
64 |
-
demo.launch()
|
|
|
1 |
+
from gradio_client import Client, handle_file
|
2 |
+
from huggingface_hub import HfApi
|
3 |
+
import time
|
4 |
|
5 |
+
api = HfApi()
|
|
|
|
|
|
|
6 |
|
7 |
+
repo_ids = ["HuggingFaceH4/idefics2-8b-playground"]
|
8 |
|
9 |
+
for repo_id in repo_ids:
|
10 |
+
if api.space_info(repo_id).runtime.stage not in ["RUNNING", "APP_STARTING", "RUNNING_APP_STARTING"]:
|
11 |
+
api.restart_space(repo_id="HuggingFaceH4/idefics2-8b-playground")
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
for repo_id in repo_ids:
|
14 |
+
while api.space_info(repo_id).runtime.stage != "RUNNING":
|
15 |
+
time.sleep(1)
|
|
|
|
|
16 |
|
17 |
+
client_idefics2 = Client("HuggingFaceH4/idefics2-8b-playground")
|
18 |
|
|
|
19 |
|
20 |
+
def respond(multimodal_input):
|
21 |
+
x = {"text": multimodal_input["text"], "files": [handle_file(file) for file in multimodal_input["files"]]}
|
22 |
+
text_1 = client_idefics2.predict(x, api_name="/predict")
|
23 |
+
return text_1
|
|
|
|
|
|
|
|
|
24 |
|
|
|
|
|
25 |
|
26 |
+
gr.Interface(
|
|
|
|
|
|
|
27 |
respond,
|
28 |
+
title="Compare IDEFICS2-8B Against DPO",
|
29 |
+
description="Chatchat made by Peterpeter8585",
|
30 |
+
inputs=[gr.MultimodalTextbox(file_types=["image"], show_label=False)],
|
31 |
+
outputs=[gr.Textbox(label="idefics2-8b")],
|
32 |
+
examples=[{"text": "What is the type of flower in the image and what insect is on it?", "files": ["./bee.jpg"]},
|
33 |
+
{"text": "Describe the image", "files": ["./howl.jpg"]}],
|
34 |
+
).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
|
|
|
|
|