Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,22 +14,30 @@ Job Description:
|
|
| 14 |
The letter should be concise, engaging, and show why the candidate is a good fit.
|
| 15 |
"""
|
| 16 |
|
| 17 |
-
# Send request to DeepSeek via PiAPI
|
| 18 |
-
response = requests.post(
|
| 19 |
-
"https://piapi.ai/api/deepseek",
|
| 20 |
-
headers={"Content-Type": "application/json"},
|
| 21 |
-
json={
|
| 22 |
-
"prompt": prompt,
|
| 23 |
-
"system": "You are a helpful assistant.",
|
| 24 |
-
"temperature": 0.8
|
| 25 |
-
}
|
| 26 |
-
)
|
| 27 |
-
|
| 28 |
try:
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
# Gradio UI
|
| 35 |
gr.Interface(
|
|
|
|
| 14 |
The letter should be concise, engaging, and show why the candidate is a good fit.
|
| 15 |
"""
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
try:
|
| 18 |
+
response = requests.post(
|
| 19 |
+
"https://piapi.ai/api/deepseek",
|
| 20 |
+
headers={"Content-Type": "application/json"},
|
| 21 |
+
json={
|
| 22 |
+
"prompt": prompt,
|
| 23 |
+
"system": "You are a helpful assistant.",
|
| 24 |
+
"temperature": 0.8
|
| 25 |
+
},
|
| 26 |
+
timeout=20 # prevent hanging
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# Check if the response body is valid JSON
|
| 30 |
+
if response.status_code == 200:
|
| 31 |
+
try:
|
| 32 |
+
data = response.json()
|
| 33 |
+
return data.get("response", "⚠️ API responded but didn't return any text.")
|
| 34 |
+
except Exception as e:
|
| 35 |
+
return f"❌ JSON decode failed — maybe HTML or empty: {str(e)}\nRaw response:\n{response.text}"
|
| 36 |
+
else:
|
| 37 |
+
return f"❌ API returned error code {response.status_code}:\n{response.text}"
|
| 38 |
+
|
| 39 |
+
except requests.exceptions.RequestException as e:
|
| 40 |
+
return f"❌ Request failed:\n{str(e)}"
|
| 41 |
|
| 42 |
# Gradio UI
|
| 43 |
gr.Interface(
|