aryn25 commited on
Commit
acda886
·
verified ·
1 Parent(s): 1849e5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -15
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
- data = response.json()
30
- return data.get("response", "⚠️ No response received from DeepSeek.")
31
- except Exception as e:
32
- return f"❌ Error: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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(