Update app.py
Browse files
app.py
CHANGED
@@ -23,15 +23,23 @@ class GPT5Model:
|
|
23 |
"prompt": full_prompt,
|
24 |
"max_tokens": 500
|
25 |
}
|
26 |
-
|
|
|
|
|
|
|
|
|
27 |
|
28 |
if response.status_code != 200:
|
29 |
-
return f"Error: {response.
|
30 |
|
31 |
try:
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
35 |
|
36 |
# -----------------------------
|
37 |
# Load API key
|
@@ -79,4 +87,3 @@ with gr.Blocks(css="""
|
|
79 |
txt.submit(respond, [txt, chatbot], [txt, chatbot])
|
80 |
|
81 |
demo.launch()
|
82 |
-
|
|
|
23 |
"prompt": full_prompt,
|
24 |
"max_tokens": 500
|
25 |
}
|
26 |
+
|
27 |
+
try:
|
28 |
+
response = requests.post("https://api.pplx.ai/v1/generate", json=data, headers=headers, timeout=15)
|
29 |
+
except requests.exceptions.RequestException as e:
|
30 |
+
return f"Error: Could not reach API. {e}"
|
31 |
|
32 |
if response.status_code != 200:
|
33 |
+
return f"Error: API key exhausted or invalid. ({response.status_code})"
|
34 |
|
35 |
try:
|
36 |
+
result = response.json()
|
37 |
+
choices = result.get("choices", [])
|
38 |
+
if not choices or "text" not in choices[0] or not choices[0]["text"].strip():
|
39 |
+
return "Error: API key exhausted or invalid."
|
40 |
+
return choices[0]["text"].strip()
|
41 |
+
except Exception:
|
42 |
+
return "Error: API key exhausted or invalid."
|
43 |
|
44 |
# -----------------------------
|
45 |
# Load API key
|
|
|
87 |
txt.submit(respond, [txt, chatbot], [txt, chatbot])
|
88 |
|
89 |
demo.launch()
|
|