AlexMia commited on
Commit
d13eccd
1 Parent(s): 2ff9a70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -14
app.py CHANGED
@@ -18,20 +18,17 @@ print("GROQ KEY: " + "RUNNING" if GROQ_API_KEY != "" else "--- NOT RUNNING ---")
18
  print("GET_AUIDO_API: " + "RUNNING\n" if GET_AUDIO_API != "" else "--- NOT RUNNING ---\n")
19
 
20
  def audio_response(text, voice="Sophia"):
21
- """
22
- Holt die Audio-Antwort von der API.
23
- """
24
  url = f"https://{GET_AUDIO_API}/get-audio?text={urllib.parse.quote(text)}&voice={voice.lower()}"
25
  print("URL GET AUDIO API: " + url)
26
  try:
27
  response = requests.get(url)
28
-
29
  print("Response: ")
30
- print(response.content.encode())
31
  return response.content
32
  except Exception as e:
33
  return f"Ein Fehler mit der GET_AUDIO_API ist aufgetreten: {e}"
34
 
 
35
  def bot(chat_msg, history=None, audio_tts_checkbox=False):
36
  """
37
  Prozessiert die Benutzereingabe und gibt eine Antwort zurück.
@@ -54,21 +51,19 @@ def bot(chat_msg, history=None, audio_tts_checkbox=False):
54
  )
55
  bot_message = completion.choices[0].message.content
56
 
57
- if audio_tts_checkbox==True:
58
- print("AUDIO TTS CHECKBOY IS TURE!")
59
  response_audio = audio_response(bot_message, voice="Sophia")
60
  print("response_audio:")
61
  print(response_audio)
62
- # messages.append({"role": "assistant", "content": (gr.Audio(response_audio.encode()) if "Ein Fehler mit der GET_AUDIO_API" not in response_audio else bot_message)})
63
- messages.append({"role": "assistant", "content": (gr.Audio(response_audio) if isinstance(response_audio, bytes) else bot_message)})
 
 
 
64
  print("2. Messages:\n")
65
  print(messages)
66
  return "", messages, ""
67
-
68
- messages.append({"role": "assistant", "content": bot_message})
69
- print("3. Messages:\n")
70
- print(messages)
71
- return "", messages, ""
72
  except Exception as e:
73
  bot_message = f"Fehler: {e}"
74
  messages.append({"role": "assistant", "content": bot_message})
 
18
  print("GET_AUIDO_API: " + "RUNNING\n" if GET_AUDIO_API != "" else "--- NOT RUNNING ---\n")
19
 
20
  def audio_response(text, voice="Sophia"):
 
 
 
21
  url = f"https://{GET_AUDIO_API}/get-audio?text={urllib.parse.quote(text)}&voice={voice.lower()}"
22
  print("URL GET AUDIO API: " + url)
23
  try:
24
  response = requests.get(url)
 
25
  print("Response: ")
26
+ print(response.content) # response.content ist bereits vom Typ 'bytes'
27
  return response.content
28
  except Exception as e:
29
  return f"Ein Fehler mit der GET_AUDIO_API ist aufgetreten: {e}"
30
 
31
+
32
  def bot(chat_msg, history=None, audio_tts_checkbox=False):
33
  """
34
  Prozessiert die Benutzereingabe und gibt eine Antwort zurück.
 
51
  )
52
  bot_message = completion.choices[0].message.content
53
 
54
+ if audio_tts_checkbox == True:
55
+ print("AUDIO TTS CHECKBOX IS TRUE!")
56
  response_audio = audio_response(bot_message, voice="Sophia")
57
  print("response_audio:")
58
  print(response_audio)
59
+ # Überprüfe, ob response_audio 'bytes' ist
60
+ if isinstance(response_audio, bytes):
61
+ messages.append({"role": "assistant", "content": gr.Audio(response_audio)})
62
+ else:
63
+ messages.append({"role": "assistant", "content": bot_message})
64
  print("2. Messages:\n")
65
  print(messages)
66
  return "", messages, ""
 
 
 
 
 
67
  except Exception as e:
68
  bot_message = f"Fehler: {e}"
69
  messages.append({"role": "assistant", "content": bot_message})