Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -247,37 +247,62 @@ def create_interface(hf_token: str):
|
|
247 |
hf_token=hf_token
|
248 |
)
|
249 |
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
281 |
)
|
282 |
|
283 |
if __name__ == "__main__":
|
|
|
247 |
hf_token=hf_token
|
248 |
)
|
249 |
|
250 |
+
# Define the inputs and outputs for the interface
|
251 |
+
inputs = [
|
252 |
+
gr.Textbox(label="User Input", lines=2),
|
253 |
+
gr.Slider(
|
254 |
+
minimum=1,
|
255 |
+
maximum=10,
|
256 |
+
step=0.5,
|
257 |
+
value=3,
|
258 |
+
label="Temperature"
|
259 |
+
),
|
260 |
+
gr.Slider(
|
261 |
+
minimum=1,
|
262 |
+
maximum=10,
|
263 |
+
step=0.5,
|
264 |
+
value=3,
|
265 |
+
label="Top P"
|
266 |
+
),
|
267 |
+
gr.Slider(
|
268 |
+
minimum=1,
|
269 |
+
maximum=3000,
|
270 |
+
value=2000,
|
271 |
+
label="Max Tokens"
|
272 |
+
),
|
273 |
+
gr.Checkbox(label="Enable Image Generation"),
|
274 |
+
]
|
275 |
+
outputs = [
|
276 |
+
gr.Chatbot(label="Assistant Response", type="messages"),
|
277 |
+
gr.Image(label="Generated Image", type="pil", visible=False),
|
278 |
+
]
|
279 |
+
|
280 |
+
def wrap_response(message, history, temp, top_p, max_tokens, image_generation_enabled):
|
281 |
+
"""Wrapper to handle the interface call."""
|
282 |
+
responses = chat.respond(
|
283 |
+
message,
|
284 |
+
history,
|
285 |
+
temperature=temp,
|
286 |
+
top_p=top_p,
|
287 |
+
max_tokens=max_tokens,
|
288 |
+
)
|
289 |
+
|
290 |
+
response_text = ""
|
291 |
+
image = None
|
292 |
+
for response in responses:
|
293 |
+
if isinstance(response, str):
|
294 |
+
response_text = response
|
295 |
+
elif isinstance(response, bytes):
|
296 |
+
image = response
|
297 |
+
|
298 |
+
return response_text, image
|
299 |
+
|
300 |
+
return gr.Interface(
|
301 |
+
fn=wrap_response,
|
302 |
+
inputs=inputs,
|
303 |
+
outputs=outputs,
|
304 |
+
live=True,
|
305 |
+
allow_flagging="never",
|
306 |
)
|
307 |
|
308 |
if __name__ == "__main__":
|