DeepLearning101 commited on
Commit
583bd83
·
verified ·
1 Parent(s): 1964be5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import gradio as gr
2
  import requests
3
- import mimetypes
4
  import json, os
5
 
6
  LLM_API = os.environ.get("LLM_API")
@@ -23,25 +22,27 @@ def send_chat_message(LLM_URL, LLM_API, user_input):
23
  json=payload,
24
  stream=True # Enable streaming
25
  )
26
- if response.status_code == 404:
27
- return "Error: Endpoint not found (404)"
28
-
 
29
  # Handle the stream of events
30
  last_thought = None
31
  try:
32
  for line in response.iter_lines(decode_unicode=True):
33
  if line:
34
  try:
 
35
  data = json.loads(line.split("data: ")[1])
36
  if data.get("event") == "agent_thought":
37
  last_thought = data.get("thought")
38
- except (IndexError, json.JSONDecodeError):
 
39
  continue
40
  except json.JSONDecodeError:
41
  return "Error: Invalid JSON response"
42
 
43
  if last_thought:
44
- # Structure the thought text
45
  return last_thought.strip()
46
  else:
47
  return "Error: No thought found in the response"
@@ -55,7 +56,7 @@ def handle_input(user_input):
55
  user_input = gr.Textbox(label='歡迎問我加密貨幣交易所的各種疑難雜症')
56
  examples = [
57
  ["MAX 帳號刪除關戶後,又重新註冊 MAX 後要怎辦?"],
58
- ["開通約定帳號"],
59
  ["客服專線?"],
60
  ["客服信箱?"]
61
  ]
@@ -77,4 +78,4 @@ with gr.Blocks() as iface:
77
  allow_flagging="never"
78
  )
79
 
80
- iface.launch()
 
1
  import gradio as gr
2
  import requests
 
3
  import json, os
4
 
5
  LLM_API = os.environ.get("LLM_API")
 
22
  json=payload,
23
  stream=True # Enable streaming
24
  )
25
+ if response.status_code != 200:
26
+ print(f"Error: {response.status_code}")
27
+ return f"Error: {response.status_code}"
28
+
29
  # Handle the stream of events
30
  last_thought = None
31
  try:
32
  for line in response.iter_lines(decode_unicode=True):
33
  if line:
34
  try:
35
+ print("Received line:", line) # Debug information
36
  data = json.loads(line.split("data: ")[1])
37
  if data.get("event") == "agent_thought":
38
  last_thought = data.get("thought")
39
+ except (IndexError, json.JSONDecodeError) as e:
40
+ print(f"Error parsing line: {line}, error: {e}") # Debug information
41
  continue
42
  except json.JSONDecodeError:
43
  return "Error: Invalid JSON response"
44
 
45
  if last_thought:
 
46
  return last_thought.strip()
47
  else:
48
  return "Error: No thought found in the response"
 
56
  user_input = gr.Textbox(label='歡迎問我加密貨幣交易所的各種疑難雜症')
57
  examples = [
58
  ["MAX 帳號刪除關戶後,又重新註冊 MAX 後要怎辦?"],
59
+ ["我要如何開通約定帳號"],
60
  ["客服專線?"],
61
  ["客服信箱?"]
62
  ]
 
78
  allow_flagging="never"
79
  )
80
 
81
+ iface.launch()