Update app.py
Browse files
app.py
CHANGED
@@ -19,7 +19,7 @@ st.set_page_config(
|
|
19 |
# Constants
|
20 |
GROQ_API_KEY = os.getenv("API_KEY") # Get API key from environment variable
|
21 |
GROQ_API_ENDPOINT = "https://api.groq.com/openai/v1/chat/completions"
|
22 |
-
MODEL = "llama-3.
|
23 |
|
24 |
# Available languages for translation
|
25 |
LANGUAGES = [
|
@@ -90,11 +90,16 @@ TRANSLATION: <translated_summary>"""
|
|
90 |
"Authorization": f"Bearer {GROQ_API_KEY}",
|
91 |
"Content-Type": "application/json"
|
92 |
}
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
payload = {
|
95 |
"model": MODEL,
|
96 |
"messages": messages,
|
97 |
-
"temperature": 0.3,
|
98 |
"max_tokens": 1024,
|
99 |
"top_p": 1
|
100 |
}
|
@@ -102,15 +107,21 @@ TRANSLATION: <translated_summary>"""
|
|
102 |
try:
|
103 |
response = requests.post(GROQ_API_ENDPOINT, headers=headers, json=payload)
|
104 |
response.raise_for_status()
|
|
|
|
|
105 |
result = response.json()
|
106 |
return {
|
107 |
"success": True,
|
108 |
"content": result["choices"][0]["message"]["content"]
|
109 |
}
|
110 |
except requests.exceptions.RequestException as e:
|
|
|
|
|
|
|
|
|
111 |
return {
|
112 |
"success": False,
|
113 |
-
"error": f"API request failed: {str(e)}"
|
114 |
}
|
115 |
except Exception as e:
|
116 |
return {
|
@@ -182,4 +193,4 @@ def main():
|
|
182 |
st.warning("Please provide either a URL or text content.")
|
183 |
|
184 |
if __name__ == "__main__":
|
185 |
-
main()
|
|
|
19 |
# Constants
|
20 |
GROQ_API_KEY = os.getenv("API_KEY") # Get API key from environment variable
|
21 |
GROQ_API_ENDPOINT = "https://api.groq.com/openai/v1/chat/completions"
|
22 |
+
MODEL = "llama-3.3-70b-versatile" # Reverting to known working model
|
23 |
|
24 |
# Available languages for translation
|
25 |
LANGUAGES = [
|
|
|
90 |
"Authorization": f"Bearer {GROQ_API_KEY}",
|
91 |
"Content-Type": "application/json"
|
92 |
}
|
93 |
+
if not GROQ_API_KEY:
|
94 |
+
return {
|
95 |
+
"success": False,
|
96 |
+
"error": "Missing API Key. Please set API_KEY in your environment."
|
97 |
+
}
|
98 |
|
99 |
payload = {
|
100 |
"model": MODEL,
|
101 |
"messages": messages,
|
102 |
+
"temperature": 0.3,
|
103 |
"max_tokens": 1024,
|
104 |
"top_p": 1
|
105 |
}
|
|
|
107 |
try:
|
108 |
response = requests.post(GROQ_API_ENDPOINT, headers=headers, json=payload)
|
109 |
response.raise_for_status()
|
110 |
+
print(f"Response status: {response.status_code}")
|
111 |
+
print(f"Response content: {response.text}")
|
112 |
result = response.json()
|
113 |
return {
|
114 |
"success": True,
|
115 |
"content": result["choices"][0]["message"]["content"]
|
116 |
}
|
117 |
except requests.exceptions.RequestException as e:
|
118 |
+
try:
|
119 |
+
error_response = response.json()
|
120 |
+
except Exception as json_err:
|
121 |
+
error_response = "No JSON response"
|
122 |
return {
|
123 |
"success": False,
|
124 |
+
"error": f"API request failed: {str(e)}. Response: {error_response}"
|
125 |
}
|
126 |
except Exception as e:
|
127 |
return {
|
|
|
193 |
st.warning("Please provide either a URL or text content.")
|
194 |
|
195 |
if __name__ == "__main__":
|
196 |
+
main()
|