Spaces:
Sleeping
Sleeping
Rob Learsch commited on
Commit ·
75bdde0
1
Parent(s): a5299e8
Update app.py
Browse files
app.py
CHANGED
|
@@ -219,96 +219,99 @@ size = 150
|
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
-
def update_artist_image(artist):
|
| 223 |
-
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
show_label=False,
|
| 241 |
-
show_fullscreen_button=False,
|
| 242 |
-
show_download_button=False,
|
| 243 |
-
show_share_button=False,
|
| 244 |
-
)
|
| 245 |
-
with gr.Column(scale=3):
|
| 246 |
-
chatbot = gr.Chatbot(height=400, type='messages')
|
| 247 |
-
|
| 248 |
-
message_input = gr.Textbox(
|
| 249 |
-
label="Your message",
|
| 250 |
-
placeholder="Enter a message and press Enter",
|
| 251 |
-
lines=2,
|
| 252 |
-
interactive=True,
|
| 253 |
-
)
|
| 254 |
-
|
| 255 |
-
# Update image when artist changes
|
| 256 |
-
artist_dropdown.change(fn=update_artist_image, inputs=artist_dropdown, outputs=artist_image)
|
| 257 |
-
|
| 258 |
-
# Define how chat works
|
| 259 |
-
def chatbot_response(message, artist, chat_history):
|
| 260 |
-
if message is None or message.strip() == "":
|
| 261 |
-
return chat_history
|
| 262 |
-
# Call your chat_with_musician function, which should return response text
|
| 263 |
-
response = chat_with_musician(message, artist)
|
| 264 |
-
chat_history = chat_history or []
|
| 265 |
-
chat_history.append((message, response))
|
| 266 |
return chat_history
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
)
|
|
|
|
| 275 |
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
#demo.launch()
|
| 279 |
-
def return_image(artist):
|
| 280 |
-
# For test: return a colored image based on artist
|
| 281 |
-
colors = {
|
| 282 |
-
"Radiohead": (255, 0, 0),
|
| 283 |
-
"Kendrick Lamar": (0, 255, 0),
|
| 284 |
-
"Grateful Dead": (0, 0, 255),
|
| 285 |
-
"Google Gemma": (255, 255, 0)
|
| 286 |
-
}
|
| 287 |
-
color = colors.get(artist, (128, 128, 128))
|
| 288 |
-
img = Image.new('RGB', (150, 150), color=color)
|
| 289 |
-
return img
|
| 290 |
-
|
| 291 |
-
def respond(message, artist, chat_history):
|
| 292 |
-
if not message:
|
| 293 |
-
return chat_history
|
| 294 |
-
reply = f"Echo ({artist}): {message}"
|
| 295 |
-
chat_history = chat_history or []
|
| 296 |
-
chat_history.append((message, reply))
|
| 297 |
-
return chat_history
|
| 298 |
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
choices=["Radiohead", "Kendrick Lamar", "Grateful Dead", "Google Gemma"],
|
| 302 |
-
value="Radiohead",
|
| 303 |
-
label="Select artist",
|
| 304 |
-
interactive=True,
|
| 305 |
-
)
|
| 306 |
-
artist_image = gr.Image(value=return_image("Radiohead"), label="Thumbnail", height=150, width=150)
|
| 307 |
|
| 308 |
-
chatbot = gr.Chatbot(height=400, type="messages")
|
| 309 |
-
message = gr.Textbox(placeholder="Enter message here...")
|
| 310 |
|
| 311 |
-
|
| 312 |
-
message.submit(fn=respond, inputs=[message, artist_dropdown, chatbot], outputs=chatbot).then(lambda: "", None, message)
|
| 313 |
|
|
|
|
|
|
|
|
|
|
| 314 |
demo.launch()
|
|
|
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
+
# def update_artist_image(artist):
|
| 223 |
+
# # Call your existing function to get the image path or PIL.Image
|
| 224 |
+
# return return_image(artist)
|
| 225 |
+
|
| 226 |
+
# with gr.Blocks() as demo:
|
| 227 |
+
# with gr.Row():
|
| 228 |
+
# with gr.Column(scale=1):
|
| 229 |
+
# artist_dropdown = gr.Dropdown(
|
| 230 |
+
# choices=["Radiohead", "Kendrick Lamar", "Grateful Dead", "Google Gemma"],
|
| 231 |
+
# value="Radiohead",
|
| 232 |
+
# label="Select artist",
|
| 233 |
+
# interactive=True,
|
| 234 |
+
# )
|
| 235 |
+
# artist_image = gr.Image(
|
| 236 |
+
# value=return_image("Radiohead"),
|
| 237 |
+
# label="Thumbnail",
|
| 238 |
+
# height=size,
|
| 239 |
+
# width=size,
|
| 240 |
+
# show_label=False,
|
| 241 |
+
# show_fullscreen_button=False,
|
| 242 |
+
# show_download_button=False,
|
| 243 |
+
# show_share_button=False,
|
| 244 |
+
# )
|
| 245 |
+
# with gr.Column(scale=3):
|
| 246 |
+
# chatbot = gr.Chatbot(height=400, type='messages')
|
| 247 |
+
|
| 248 |
+
# message_input = gr.Textbox(
|
| 249 |
+
# label="Your message",
|
| 250 |
+
# placeholder="Enter a message and press Enter",
|
| 251 |
+
# lines=2,
|
| 252 |
+
# interactive=True,
|
| 253 |
+
# )
|
| 254 |
+
|
| 255 |
+
# # Update image when artist changes
|
| 256 |
+
# artist_dropdown.change(fn=update_artist_image, inputs=artist_dropdown, outputs=artist_image)
|
| 257 |
+
|
| 258 |
+
# # Define how chat works
|
| 259 |
+
# def chatbot_response(message, artist, chat_history):
|
| 260 |
+
# if message is None or message.strip() == "":
|
| 261 |
+
# return chat_history
|
| 262 |
+
# # Call your chat_with_musician function, which should return response text
|
| 263 |
+
# response = chat_with_musician(message, artist)
|
| 264 |
+
# chat_history = chat_history or []
|
| 265 |
+
# chat_history.append((message, response))
|
| 266 |
+
# return chat_history
|
| 267 |
+
|
| 268 |
+
# # Wire message input submit to update chatbot
|
| 269 |
+
# message_input.submit(
|
| 270 |
+
# fn=chatbot_response,
|
| 271 |
+
# inputs=[message_input, artist_dropdown, chatbot],
|
| 272 |
+
# outputs=chatbot,
|
| 273 |
+
# queue=False,
|
| 274 |
+
# ).then(lambda: "", None, message_input) # Clear input after submit
|
| 275 |
|
| 276 |
+
def return_image(artist):
|
| 277 |
+
# For test: return a colored image based on artist
|
| 278 |
+
colors = {
|
| 279 |
+
"Radiohead": (255, 0, 0),
|
| 280 |
+
"Kendrick Lamar": (0, 255, 0),
|
| 281 |
+
"Grateful Dead": (0, 0, 255),
|
| 282 |
+
"Google Gemma": (255, 255, 0)
|
| 283 |
+
}
|
| 284 |
+
color = colors.get(artist, (128, 128, 128))
|
| 285 |
+
img = Image.new('RGB', (150, 150), color=color)
|
| 286 |
+
return img
|
| 287 |
+
|
| 288 |
+
def respond(message, artist, chat_history):
|
| 289 |
+
if not message:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
return chat_history
|
| 291 |
+
reply = f"Echo ({artist}): {message}"
|
| 292 |
+
chat_history = chat_history or []
|
| 293 |
+
chat_history.append((message, reply))
|
| 294 |
+
return chat_history
|
| 295 |
|
| 296 |
+
with gr.Blocks() as demo:
|
| 297 |
+
artist_dropdown = gr.Dropdown(
|
| 298 |
+
choices=["Radiohead", "Kendrick Lamar", "Grateful Dead", "Google Gemma"],
|
| 299 |
+
value="Radiohead",
|
| 300 |
+
label="Select artist",
|
| 301 |
+
interactive=True,
|
| 302 |
+
)
|
| 303 |
+
artist_image = gr.Image(value=return_image("Radiohead"), label="Thumbnail", height=150, width=150)
|
| 304 |
|
| 305 |
+
chatbot = gr.Chatbot(height=400, type="messages")
|
| 306 |
+
message = gr.Textbox(placeholder="Enter message here...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
|
| 308 |
+
artist_dropdown.change(fn=return_image, inputs=artist_dropdown, outputs=artist_image)
|
| 309 |
+
message.submit(fn=respond, inputs=[message, artist_dropdown, chatbot], outputs=chatbot).then(lambda: "", None, message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
|
|
|
|
|
|
|
| 311 |
|
| 312 |
+
# Launch app
|
|
|
|
| 313 |
|
| 314 |
+
if __name__ == "__main__":
|
| 315 |
+
#demo.launch()
|
| 316 |
+
|
| 317 |
demo.launch()
|