Rob Learsch commited on
Commit
0a86385
·
1 Parent(s): 5ab3495

chatgpt rewrites app for gradio > 4.0

Browse files
Files changed (1) hide show
  1. app.py +58 -47
app.py CHANGED
@@ -206,57 +206,68 @@ all_phrases_grateful_dead = generate_cumulative_phrases(songs_from_text(grateful
206
  size = 350 #256
207
 
208
  # Initialize Hugging Face Inference Client
209
- client = InferenceClient(#provider="hf-inference",
210
- token=HF_API_KEY)
211
-
212
- #system_message = "Please limit your response to only a few sentences."
213
- #system_message = "Be creative and imprecise with your word choice. And don't be too repetitive. Please limit your respone to only a few sentences."
214
- system_message = "Don't be too repetitive. Please limit your respone to only a few sentences."
215
- system_message_repeated = "Be creative and imprecise with your word choice. Limit your response to a few sentences"
216
- #Function to generate chatbot responses
217
-
218
- artist_history = [""] # Variable to keep track of the previous artist
219
- Artist_dropdown = gr.Dropdown(choices=["Radiohead", "Kendrick Lamar","Grateful Dead","Google Gemma"],
220
- value="Radiohead",
221
- label="Select artist",
222
- #info="More coming soon"
223
- )
224
- Arist_image = gr.Image(
225
- value=return_image("Radiohead"),
226
- label="Thumbnail",height=size, width=size,
227
- show_label=False,
228
- show_fullscreen_button=False,
229
- show_download_button=False,
230
- show_share_button=False,
231
- )
232
- #Chatbot = gr.Chatbot()
233
  with gr.Blocks() as demo:
234
- # gr.Markdown("### Select your flavor.")
235
- #with gr.Row(equal_height=True):
236
  with gr.Row():
237
  with gr.Column(scale=1):
238
- gr.Interface(
239
- fn = return_image,
240
- outputs = Arist_image,
241
- inputs = Artist_dropdown,
242
- live=True,
243
- clear_btn=None,
244
  )
245
- with gr.Column(scale=3):
246
- chatbot = gr.Chatbot(height=400,
247
- type='messages',)
248
- gr.ChatInterface(
249
- chat_with_musician,
250
- additional_inputs=[Artist_dropdown],
251
- type="messages",
252
- title="Lyrical Language Model",
253
- description="Enter a message, receive vibes",
254
- fill_height=False,
255
- chatbot=chatbot,
256
  )
257
-
258
- # Launch the chatbot
259
- if __name__ == "__main__":
260
- demo.launch()
261
 
 
 
 
 
 
 
262
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  size = 350 #256
207
 
208
  # Initialize Hugging Face Inference Client
209
+ client = InferenceClient(token=HF_API_KEY)
210
+
211
+ system_message = "Don't be too repetitive. Please limit your response to only a few sentences."
212
+
213
+ artist_history = [""] # If you want to track previous artist selection
214
+
215
+ # Size for the image thumbnail (set your size)
216
+ size = 150
217
+
218
+ def update_artist_image(artist):
219
+ # Call your existing function to get the image path or PIL.Image
220
+ return return_image(artist)
221
+
 
 
 
 
 
 
 
 
 
 
 
222
  with gr.Blocks() as demo:
 
 
223
  with gr.Row():
224
  with gr.Column(scale=1):
225
+ artist_dropdown = gr.Dropdown(
226
+ choices=["Radiohead", "Kendrick Lamar", "Grateful Dead", "Google Gemma"],
227
+ value="Radiohead",
228
+ label="Select artist",
 
 
229
  )
230
+ artist_image = gr.Image(
231
+ value=return_image("Radiohead"),
232
+ label="Thumbnail",
233
+ height=size,
234
+ width=size,
235
+ show_label=False,
236
+ show_fullscreen_button=False,
237
+ show_download_button=False,
238
+ show_share_button=False,
 
 
239
  )
240
+ with gr.Column(scale=3):
241
+ chatbot = gr.Chatbot(height=400, type='messages')
 
 
242
 
243
+ message_input = gr.Textbox(
244
+ label="Your message",
245
+ placeholder="Enter a message and press Enter",
246
+ lines=2,
247
+ interactive=True,
248
+ )
249
 
250
+ # Update image when artist changes
251
+ artist_dropdown.change(fn=update_artist_image, inputs=artist_dropdown, outputs=artist_image)
252
+
253
+ # Define how chat works
254
+ def chatbot_response(message, artist, chat_history):
255
+ if message is None or message.strip() == "":
256
+ return chat_history
257
+ # Call your chat_with_musician function, which should return response text
258
+ response = chat_with_musician(message, artist)
259
+ chat_history = chat_history or []
260
+ chat_history.append((message, response))
261
+ return chat_history
262
+
263
+ # Wire message input submit to update chatbot
264
+ message_input.submit(
265
+ fn=chatbot_response,
266
+ inputs=[message_input, artist_dropdown, chatbot],
267
+ outputs=chatbot,
268
+ queue=False,
269
+ ).then(lambda: "", None, message_input) # Clear input after submit
270
+
271
+ # Launch app
272
+ if __name__ == "__main__":
273
+ demo.launch()