Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,8 +4,7 @@ from huggingface_hub import InferenceClient
|
|
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("
|
8 |
-
|
9 |
|
10 |
def respond(
|
11 |
message,
|
@@ -14,6 +13,7 @@ def respond(
|
|
14 |
max_tokens,
|
15 |
temperature,
|
16 |
top_p,
|
|
|
17 |
):
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
|
@@ -25,21 +25,27 @@ def respond(
|
|
25 |
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
response = ""
|
29 |
|
30 |
for message in client.chat_completion(
|
31 |
-
|
32 |
-
max_tokens=max_tokens,
|
33 |
stream=True,
|
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 |
"""
|
44 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
"""
|
@@ -56,9 +62,9 @@ demo = gr.ChatInterface(
|
|
56 |
step=0.05,
|
57 |
label="Top-p (nucleus sampling)",
|
58 |
),
|
|
|
59 |
],
|
60 |
)
|
61 |
|
62 |
-
|
63 |
if __name__ == "__main__":
|
64 |
demo.launch()
|
|
|
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("AI-Safeguard/Ivy-VL-llava")
|
|
|
8 |
|
9 |
def respond(
|
10 |
message,
|
|
|
13 |
max_tokens,
|
14 |
temperature,
|
15 |
top_p,
|
16 |
+
image=None,
|
17 |
):
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
|
|
|
25 |
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
+
payload = {
|
29 |
+
"messages": messages,
|
30 |
+
"max_tokens": max_tokens,
|
31 |
+
"temperature": temperature,
|
32 |
+
"top_p": top_p,
|
33 |
+
}
|
34 |
+
|
35 |
+
if image is not None:
|
36 |
+
payload["image"] = image
|
37 |
+
|
38 |
response = ""
|
39 |
|
40 |
for message in client.chat_completion(
|
41 |
+
payload,
|
|
|
42 |
stream=True,
|
|
|
|
|
43 |
):
|
44 |
token = message.choices[0].delta.content
|
45 |
|
46 |
response += token
|
47 |
yield response
|
48 |
|
|
|
49 |
"""
|
50 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
51 |
"""
|
|
|
62 |
step=0.05,
|
63 |
label="Top-p (nucleus sampling)",
|
64 |
),
|
65 |
+
gr.Image(type="filepath", label="Input Image (optional)"),
|
66 |
],
|
67 |
)
|
68 |
|
|
|
69 |
if __name__ == "__main__":
|
70 |
demo.launch()
|