Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -209,99 +209,15 @@ def handle_tool_call(message):
|
|
| 209 |
# return tool_outputs
|
| 210 |
|
| 211 |
# gr.ChatInterface(fn=chat2, type="messages").launch()
|
| 212 |
-
|
| 213 |
-
# gr.ChatInterface(
|
| 214 |
-
# fn=chat2,
|
| 215 |
-
# type="messages",
|
| 216 |
-
# title="Welcome to Austa Kitchen", # Title shown at the top of the interface
|
| 217 |
-
# description="Ask me anything about Austa Kitchen!" # Label shown below the title
|
| 218 |
-
# ).launch(share = True, debug=True)
|
| 219 |
-
|
| 220 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
|
| 222 |
-
#
|
| 223 |
-
# def chat2(message, history):
|
| 224 |
-
# # Your chat logic here
|
| 225 |
-
# # Should return updated history
|
| 226 |
-
# return history
|
| 227 |
-
|
| 228 |
-
with gr.Blocks(title="Welcome to Austa Kitchen") as ui:
|
| 229 |
-
# Title and description
|
| 230 |
-
gr.Markdown("# Welcome to Austa Kitchen")
|
| 231 |
-
gr.Markdown("Ask me anything about Austa Kitchen!")
|
| 232 |
-
|
| 233 |
-
with gr.Row():
|
| 234 |
-
with gr.Column():
|
| 235 |
-
# Chat interface
|
| 236 |
-
chatbot = gr.Chatbot(
|
| 237 |
-
height=500,
|
| 238 |
-
type="messages",
|
| 239 |
-
show_label=False
|
| 240 |
-
)
|
| 241 |
-
|
| 242 |
-
with gr.Row():
|
| 243 |
-
with gr.Column():
|
| 244 |
-
# Input textbox
|
| 245 |
-
msg = gr.Textbox(
|
| 246 |
-
label="Type your message here...",
|
| 247 |
-
placeholder="Ask me anything about Austa Kitchen!",
|
| 248 |
-
show_label=False,
|
| 249 |
-
container=False
|
| 250 |
-
)
|
| 251 |
-
|
| 252 |
-
with gr.Row():
|
| 253 |
-
# Buttons
|
| 254 |
-
submit_btn = gr.Button("Send", variant="primary")
|
| 255 |
-
clear_btn = gr.Button("Clear", variant="secondary")
|
| 256 |
-
|
| 257 |
-
# Helper function to handle user input
|
| 258 |
-
def user_input(message, history):
|
| 259 |
-
if message.strip():
|
| 260 |
-
# Add user message to history
|
| 261 |
-
history.append({"role": "user", "content": message})
|
| 262 |
-
return "", history
|
| 263 |
-
|
| 264 |
-
# Helper function to get bot response
|
| 265 |
-
def bot_response(history):
|
| 266 |
-
if history and history[-1]["role"] == "user":
|
| 267 |
-
# Call your chat2 function
|
| 268 |
-
updated_history = chat2(history[-1]["content"], history)
|
| 269 |
-
return updated_history
|
| 270 |
-
return history
|
| 271 |
-
|
| 272 |
-
# Event handlers
|
| 273 |
-
msg.submit(
|
| 274 |
-
user_input,
|
| 275 |
-
inputs=[msg, chatbot],
|
| 276 |
-
outputs=[msg, chatbot],
|
| 277 |
-
queue=False
|
| 278 |
-
).then(
|
| 279 |
-
bot_response,
|
| 280 |
-
inputs=[chatbot],
|
| 281 |
-
outputs=[chatbot]
|
| 282 |
-
)
|
| 283 |
-
|
| 284 |
-
submit_btn.click(
|
| 285 |
-
user_input,
|
| 286 |
-
inputs=[msg, chatbot],
|
| 287 |
-
outputs=[msg, chatbot],
|
| 288 |
-
queue=False
|
| 289 |
-
).then(
|
| 290 |
-
bot_response,
|
| 291 |
-
inputs=[chatbot],
|
| 292 |
-
outputs=[chatbot]
|
| 293 |
-
)
|
| 294 |
-
|
| 295 |
-
clear_btn.click(
|
| 296 |
-
lambda: ([], ""),
|
| 297 |
-
outputs=[chatbot, msg],
|
| 298 |
-
queue=False
|
| 299 |
-
)
|
| 300 |
-
|
| 301 |
-
# Launch for Hugging Face Spaces
|
| 302 |
-
ui.launch()
|
| 303 |
-
|
| 304 |
-
|
| 305 |
|
| 306 |
import base64
|
| 307 |
from io import BytesIO
|
|
@@ -329,23 +245,6 @@ from io import BytesIO
|
|
| 329 |
from PIL import Image
|
| 330 |
from IPython.display import Audio, display
|
| 331 |
|
| 332 |
-
# def talker(message):
|
| 333 |
-
# response = openai.audio.speech.create(
|
| 334 |
-
# model="tts-1",
|
| 335 |
-
# voice = "ash",
|
| 336 |
-
# # voice = "shimmer",
|
| 337 |
-
# # voice="onyx",
|
| 338 |
-
# input=message)
|
| 339 |
-
|
| 340 |
-
# audio_stream = BytesIO(response.content)
|
| 341 |
-
# output_filename = "output_audio.mp3"
|
| 342 |
-
# with open(output_filename, "wb") as f:
|
| 343 |
-
# f.write(audio_stream.read())
|
| 344 |
-
|
| 345 |
-
# # Play the generated audio
|
| 346 |
-
# display(Audio(output_filename, autoplay=True))
|
| 347 |
-
|
| 348 |
-
# talker("Well, hi there")
|
| 349 |
|
| 350 |
|
| 351 |
|
|
@@ -368,75 +267,4 @@ def chat(history):
|
|
| 368 |
# Comment out or delete the next line if you'd rather skip Audio for now..
|
| 369 |
# talker(reply)
|
| 370 |
|
| 371 |
-
return history, image
|
| 372 |
-
|
| 373 |
-
# More involved Gradio code as we're not using the preset Chat interface!
|
| 374 |
-
# Passing in inbrowser=True in the last line will cause a Gradio window to pop up immediately.
|
| 375 |
-
|
| 376 |
-
# with gr.Blocks() as ui:
|
| 377 |
-
# with gr.Row():
|
| 378 |
-
# chatbot = gr.Chatbot(height=500, type="messages")
|
| 379 |
-
# image_output = gr.Image(height=500)
|
| 380 |
-
# with gr.Row():
|
| 381 |
-
# entry = gr.Textbox(label="Welcome to Austa Kitchen:")
|
| 382 |
-
|
| 383 |
-
# with gr.Row():
|
| 384 |
-
# clear = gr.Button("Clear")
|
| 385 |
-
|
| 386 |
-
# def do_entry(message, history):
|
| 387 |
-
# history += [{"role":"user", "content":message}]
|
| 388 |
-
# return "", history
|
| 389 |
-
|
| 390 |
-
# entry.submit(do_entry, inputs=[entry, chatbot], outputs=[entry, chatbot]).then(
|
| 391 |
-
# chat, inputs=chatbot, outputs=[chatbot, image_output]
|
| 392 |
-
# )
|
| 393 |
-
# clear.click(lambda: None, inputs=None, outputs=chatbot, queue=False).launch(inbrowser=True, share=True, debug=True)
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
#Gradio2
|
| 397 |
-
import gradio as gr
|
| 398 |
-
|
| 399 |
-
# Your chat function should be defined somewhere above this
|
| 400 |
-
# def chat(history):
|
| 401 |
-
# # Your chat logic here
|
| 402 |
-
# return history, image
|
| 403 |
-
|
| 404 |
-
# with gr.Blocks() as ui:
|
| 405 |
-
# with gr.Row():
|
| 406 |
-
# chatbot = gr.Chatbot(height=500, type="messages")
|
| 407 |
-
# image_output = gr.Image(height=500)
|
| 408 |
-
|
| 409 |
-
# with gr.Row():
|
| 410 |
-
# entry = gr.Textbox(label="Welcome to Austa Kitchen:")
|
| 411 |
-
|
| 412 |
-
# with gr.Row():
|
| 413 |
-
# clear = gr.Button("Clear")
|
| 414 |
-
|
| 415 |
-
# def do_entry(message, history):
|
| 416 |
-
# history += [{"role": "user", "content": message}]
|
| 417 |
-
# return "", history
|
| 418 |
-
|
| 419 |
-
# # Set up the event handlers
|
| 420 |
-
# entry.submit(
|
| 421 |
-
# do_entry,
|
| 422 |
-
# inputs=[entry, chatbot],
|
| 423 |
-
# outputs=[entry, chatbot]
|
| 424 |
-
# ).then(
|
| 425 |
-
# chat,
|
| 426 |
-
# inputs=chatbot,
|
| 427 |
-
# outputs=[chatbot, image_output]
|
| 428 |
-
# )
|
| 429 |
-
|
| 430 |
-
# # Clear button handler
|
| 431 |
-
# clear.click(
|
| 432 |
-
# lambda: (None, None), # Clear both chatbot and image
|
| 433 |
-
# inputs=None,
|
| 434 |
-
# outputs=[chatbot, image_output],
|
| 435 |
-
# queue=False
|
| 436 |
-
# )
|
| 437 |
-
|
| 438 |
-
# # Launch the interface for Hugging Face Spaces
|
| 439 |
-
# ui.launch()
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
|
|
|
| 209 |
# return tool_outputs
|
| 210 |
|
| 211 |
# gr.ChatInterface(fn=chat2, type="messages").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
import gradio as gr
|
| 213 |
+
gr.ChatInterface(
|
| 214 |
+
fn=chat2,
|
| 215 |
+
type="messages",
|
| 216 |
+
title="Welcome to Austa Kitchen", # Title shown at the top of the interface
|
| 217 |
+
description="Ask me anything about Austa Kitchen!" # Label shown below the title
|
| 218 |
+
).launch(share = True, debug=True)
|
| 219 |
|
| 220 |
+
#for Image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
|
| 222 |
import base64
|
| 223 |
from io import BytesIO
|
|
|
|
| 245 |
from PIL import Image
|
| 246 |
from IPython.display import Audio, display
|
| 247 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
|
| 249 |
|
| 250 |
|
|
|
|
| 267 |
# Comment out or delete the next line if you'd rather skip Audio for now..
|
| 268 |
# talker(reply)
|
| 269 |
|
| 270 |
+
return history, image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|