AlexMia commited on
Commit
491aac8
1 Parent(s): 7b9bbdd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -11
app.py CHANGED
@@ -15,7 +15,7 @@ def audio_response(text, voice="Sophia"): # Alex
15
  response = requests.get(url)
16
  return gr.Audio("response.content")
17
  except Exception as e:
18
- return f"Fehler: {e}", ""
19
 
20
 
21
  def bot(chat_msg, history=None, audio_response=False):
@@ -46,9 +46,9 @@ def bot(chat_msg, history=None, audio_response=False):
46
  )
47
  bot_message = completion.choices[0].message.content
48
  if audio_response:
49
- response = audio_response(bot_message, voice="Sophia")
50
  time.sleep(1)
51
- return "", response if not "error" in response else bot_message, ""
52
  except Exception as e:
53
  bot_message = f"Fehler: {e}"
54
  return "", bot_message, ""
@@ -60,13 +60,6 @@ with gr.Blocks() as demo:
60
  audio_response = gr.Checkbox(label="Audio Antwort generieren?", value=False)
61
  clear = gr.ClearButton([chat_input, chatbot, audio_response], show_api=False)
62
 
63
- def respond(message, chat_history):
64
- bot_message = random.choice(["How are you?", "Today is a great day", "I'm very hungry"])
65
- chat_history.append({"role": "user", "content": message})
66
- chat_history.append({"role": "assistant", "content": bot_message})
67
- time.sleep(2)
68
- return "", chat_history
69
-
70
- chat_input.submit(respond, [chat_input, chatbot, audio_response], [chat_input, chatbot, audio_response], api_name="llm_inference")
71
 
72
  demo.launch()
 
15
  response = requests.get(url)
16
  return gr.Audio("response.content")
17
  except Exception as e:
18
+ return f"Ein Fehler mit der GET_AUDIO_API ist aufgetreten: {e}", ""
19
 
20
 
21
  def bot(chat_msg, history=None, audio_response=False):
 
46
  )
47
  bot_message = completion.choices[0].message.content
48
  if audio_response:
49
+ response_audio = audio_response(bot_message, voice="Sophia")
50
  time.sleep(1)
51
+ return "", response_audio if not "Ein Fehler mit der GET_AUDIO_API" in response_audio else bot_message, ""
52
  except Exception as e:
53
  bot_message = f"Fehler: {e}"
54
  return "", bot_message, ""
 
60
  audio_response = gr.Checkbox(label="Audio Antwort generieren?", value=False)
61
  clear = gr.ClearButton([chat_input, chatbot, audio_response], show_api=False)
62
 
63
+ chat_input.submit(bot, [chat_input, chatbot, audio_response], [chat_input, chatbot, audio_response], api_name="llm_inference")
 
 
 
 
 
 
 
64
 
65
  demo.launch()