Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
from gradio_client.utils import encode_url_or_file_to_base64
|
3 |
from huggingface_hub import InferenceClient
|
4 |
|
5 |
-
def chat_1(history, prompt, image, oauth_token: gr.OAuthToken | None):
|
6 |
if oauth_token is None:
|
7 |
raise ValueError("Please log in to use this Space.")
|
8 |
|
@@ -22,13 +22,15 @@ def chat_1(history, prompt, image, oauth_token: gr.OAuthToken | None):
|
|
22 |
}
|
23 |
]
|
24 |
if image is not None:
|
|
|
25 |
content.append({
|
26 |
"type": "image_url",
|
27 |
"image_url": {
|
28 |
-
"url":
|
29 |
}
|
30 |
})
|
31 |
|
|
|
32 |
yield history + user_messages
|
33 |
|
34 |
messages = [
|
@@ -45,13 +47,6 @@ def chat_1(history, prompt, image, oauth_token: gr.OAuthToken | None):
|
|
45 |
stream=True,
|
46 |
)
|
47 |
|
48 |
-
if image is not None:
|
49 |
-
user_messages.append({
|
50 |
-
"type": "image_url",
|
51 |
-
"image_url": {
|
52 |
-
"url": encode_url_or_file_to_base64(image)
|
53 |
-
}
|
54 |
-
})
|
55 |
response = ""
|
56 |
for chunk in stream:
|
57 |
if chunk.choices:
|
@@ -59,7 +54,7 @@ def chat_1(history, prompt, image, oauth_token: gr.OAuthToken | None):
|
|
59 |
yield history + user_messages + [{"role": "assistant", "content": response}]
|
60 |
|
61 |
|
62 |
-
def chat_2(history, prompt, image, oauth_token: gr.OAuthToken | None):
|
63 |
if oauth_token is None:
|
64 |
raise ValueError("Please log in to use this Space.")
|
65 |
|
@@ -79,10 +74,11 @@ def chat_2(history, prompt, image, oauth_token: gr.OAuthToken | None):
|
|
79 |
}
|
80 |
]
|
81 |
if image is not None:
|
|
|
82 |
content.append({
|
83 |
"type": "image_url",
|
84 |
"image_url": {
|
85 |
-
"url":
|
86 |
}
|
87 |
})
|
88 |
|
@@ -102,13 +98,6 @@ def chat_2(history, prompt, image, oauth_token: gr.OAuthToken | None):
|
|
102 |
stream=True,
|
103 |
)
|
104 |
|
105 |
-
if image is not None:
|
106 |
-
user_messages.append({
|
107 |
-
"type": "image_url",
|
108 |
-
"image_url": {
|
109 |
-
"url": encode_url_or_file_to_base64(image)
|
110 |
-
}
|
111 |
-
})
|
112 |
response = ""
|
113 |
for chunk in stream:
|
114 |
if chunk.choices:
|
|
|
2 |
from gradio_client.utils import encode_url_or_file_to_base64
|
3 |
from huggingface_hub import InferenceClient
|
4 |
|
5 |
+
def chat_1(history, prompt, image, oauth_token: gr.OAuthToken | None, request: gr.Request):
|
6 |
if oauth_token is None:
|
7 |
raise ValueError("Please log in to use this Space.")
|
8 |
|
|
|
22 |
}
|
23 |
]
|
24 |
if image is not None:
|
25 |
+
file_url = str(request.url).replace("queue/join", "file=") + image
|
26 |
content.append({
|
27 |
"type": "image_url",
|
28 |
"image_url": {
|
29 |
+
"url": file_url
|
30 |
}
|
31 |
})
|
32 |
|
33 |
+
|
34 |
yield history + user_messages
|
35 |
|
36 |
messages = [
|
|
|
47 |
stream=True,
|
48 |
)
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
response = ""
|
51 |
for chunk in stream:
|
52 |
if chunk.choices:
|
|
|
54 |
yield history + user_messages + [{"role": "assistant", "content": response}]
|
55 |
|
56 |
|
57 |
+
def chat_2(history, prompt, image, oauth_token: gr.OAuthToken | None, request: gr.Request):
|
58 |
if oauth_token is None:
|
59 |
raise ValueError("Please log in to use this Space.")
|
60 |
|
|
|
74 |
}
|
75 |
]
|
76 |
if image is not None:
|
77 |
+
file_url = str(request.url).replace("queue/join", "file=") + image
|
78 |
content.append({
|
79 |
"type": "image_url",
|
80 |
"image_url": {
|
81 |
+
"url": file_url
|
82 |
}
|
83 |
})
|
84 |
|
|
|
98 |
stream=True,
|
99 |
)
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
response = ""
|
102 |
for chunk in stream:
|
103 |
if chunk.choices:
|