Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,7 @@ tts_model = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=
|
|
| 11 |
|
| 12 |
# Groq API Key and Base URL
|
| 13 |
groq_api_key = "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"
|
| 14 |
-
groq_base_url = "https://api.groq.com" #
|
| 15 |
|
| 16 |
# Functions for the Chatbot
|
| 17 |
def voice_to_text(audio_path):
|
|
@@ -22,7 +22,7 @@ def voice_to_text(audio_path):
|
|
| 22 |
|
| 23 |
def process_text_with_groq(input_text):
|
| 24 |
"""Process user text input using Groq LLM."""
|
| 25 |
-
url = f"{groq_base_url}/chat/completions" #
|
| 26 |
headers = {"Authorization": f"Bearer {groq_api_key}"}
|
| 27 |
payload = {
|
| 28 |
"messages": [{"role": "user", "content": input_text}],
|
|
@@ -32,9 +32,11 @@ def process_text_with_groq(input_text):
|
|
| 32 |
try:
|
| 33 |
response = requests.post(url, json=payload, headers=headers)
|
| 34 |
response.raise_for_status() # Raise an error for HTTP issues
|
| 35 |
-
return response.json()
|
| 36 |
-
except requests.exceptions.
|
| 37 |
-
return f"
|
|
|
|
|
|
|
| 38 |
|
| 39 |
def translate_text(text, target_lang):
|
| 40 |
"""Translate text to the target language using deep-translator."""
|
|
|
|
| 11 |
|
| 12 |
# Groq API Key and Base URL
|
| 13 |
groq_api_key = "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"
|
| 14 |
+
groq_base_url = "https://api.groq.com" # Replace this with the correct base URL if needed
|
| 15 |
|
| 16 |
# Functions for the Chatbot
|
| 17 |
def voice_to_text(audio_path):
|
|
|
|
| 22 |
|
| 23 |
def process_text_with_groq(input_text):
|
| 24 |
"""Process user text input using Groq LLM."""
|
| 25 |
+
url = f"{groq_base_url}/chat/completions" # Replace with the correct endpoint from Groq documentation
|
| 26 |
headers = {"Authorization": f"Bearer {groq_api_key}"}
|
| 27 |
payload = {
|
| 28 |
"messages": [{"role": "user", "content": input_text}],
|
|
|
|
| 32 |
try:
|
| 33 |
response = requests.post(url, json=payload, headers=headers)
|
| 34 |
response.raise_for_status() # Raise an error for HTTP issues
|
| 35 |
+
return response.json().get("choices", [{}])[0].get("message", {}).get("content", "No response received.")
|
| 36 |
+
except requests.exceptions.HTTPError as http_err:
|
| 37 |
+
return f"HTTP error occurred: {http_err}"
|
| 38 |
+
except Exception as e:
|
| 39 |
+
return f"An error occurred: {str(e)}"
|
| 40 |
|
| 41 |
def translate_text(text, target_lang):
|
| 42 |
"""Translate text to the target language using deep-translator."""
|