Fric7ion commited on
Commit
2244ca0
1 Parent(s): e0ce0ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -5,20 +5,22 @@ import requests
5
  url = "https://fric7ion-fricfast.hf.space/chat"
6
 
7
  def chatgpt(message, history):
8
- response = requests.post(url, params={"prompt": message, "max_token": "140"})
9
- print("Raw response:", response.text)
10
- if response.text: # Check if the response is not empty
11
- try:
12
- data = response.json() # Try to parse the response as JSON
13
- print(data) # Print the parsed JSON data
14
- reply = data.get('message', '') # Extract the 'message' field from the JSON, default to empty string if not present
15
- except ValueError: # Catch any JSON decoding errors
16
- print("Error decoding JSON")
17
- reply = "Error: Unable to process response"
18
- else:
19
- print("Empty response")
20
- reply = "Error: No response from server"
 
21
  return reply
 
22
  iface = gr.Blocks()
23
 
24
  with iface:
 
5
  url = "https://fric7ion-fricfast.hf.space/chat"
6
 
7
  def chatgpt(message, history):
8
+ try:
9
+ # Attempt to make the external request
10
+ response = requests.post(url, params={"prompt": message, "max_token": "140"})
11
+ print("Raw response:", response.text)
12
+ if response.text:
13
+ data = response.json()
14
+ print(data)
15
+ reply = data.get('message', '')
16
+ else:
17
+ print("Empty response")
18
+ reply = "Error: No response from server"
19
+ except Exception as e:
20
+ print("Error making external request:", e)
21
+ reply = "Error: Unable to process request"
22
  return reply
23
+
24
  iface = gr.Blocks()
25
 
26
  with iface: