Julian Vanecek commited on
Commit
4a3b0d1
·
1 Parent(s): 51ae606

reverting frontend

Browse files
Files changed (1) hide show
  1. app.py +10 -30
app.py CHANGED
@@ -68,33 +68,17 @@ def process_faq(question, user_id="anonymous", model="claude-sonnet"):
68
  print(f"DEBUG: Sending to {lambda_url}")
69
  print(f"DEBUG: Payload: {json.dumps(payload, indent=2)}")
70
 
71
- # Make the API call with streaming
72
- with requests.post(
73
  lambda_url,
74
  headers={"Content-Type": "application/json"},
75
- json=payload,
76
- stream=True
77
- ) as response:
78
- if response.status_code != 200:
79
- return f"Error: Lambda function returned status code {response.status_code}"
80
-
81
- # Process the streaming response
82
- full_response = ""
83
- for chunk in response.iter_content(chunk_size=1024, decode_unicode=True):
84
- if chunk:
85
- try:
86
- # Try to parse the chunk as JSON
87
- chunk_data = json.loads(chunk)
88
- if "response" in chunk_data:
89
- chunk_text = chunk_data["response"]
90
- full_response += chunk_text
91
- yield full_response
92
- except json.JSONDecodeError:
93
- # If not JSON, treat as plain text
94
- full_response += chunk
95
- yield full_response
96
-
97
- return full_response
98
 
99
  except Exception as e:
100
  return f"Error processing FAQ: {str(e)}"
@@ -143,11 +127,7 @@ def execute_elasticsearch_query(query_body):
143
 
144
  # --- Gradio v4.x UI ---
145
  def faq_wrapper(question, user_id, model):
146
- # Gradio expects a non-generator for Interface
147
- result = ""
148
- for chunk in process_faq(question, user_id, model):
149
- result = chunk
150
- return result
151
 
152
  def elasticsearch_generate(natural_input):
153
  return natural_to_query(natural_input)
 
68
  print(f"DEBUG: Sending to {lambda_url}")
69
  print(f"DEBUG: Payload: {json.dumps(payload, indent=2)}")
70
 
71
+ # Make the API call
72
+ response = requests.post(
73
  lambda_url,
74
  headers={"Content-Type": "application/json"},
75
+ json=payload
76
+ )
77
+
78
+ if response.status_code != 200:
79
+ return f"Error: Lambda function returned status code {response.status_code}"
80
+
81
+ return response.text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  except Exception as e:
84
  return f"Error processing FAQ: {str(e)}"
 
127
 
128
  # --- Gradio v4.x UI ---
129
  def faq_wrapper(question, user_id, model):
130
+ return process_faq(question, user_id, model)
 
 
 
 
131
 
132
  def elasticsearch_generate(natural_input):
133
  return natural_to_query(natural_input)