theboulder123 commited on
Commit
462e263
·
verified ·
1 Parent(s): 015a392

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -5,22 +5,34 @@ import requests
5
  KAGGLE_BACKEND_URL = "https://gauchely-nonreconcilable-miracle.ngrok-free.dev"
6
 
7
  def chat_with_buddy(message, history):
8
- # Package your prompt for the Kaggle FastAPI architecture
9
  payload = {"prompt": message}
10
 
 
 
 
 
 
 
11
  try:
12
- # Fire the HTTP request directly over the web to your Kaggle dual-T4 GPUs
13
- response = requests.post(f"{KAGGLE_BACKEND_URL}/generate", json=payload)
 
 
 
 
 
14
 
15
  if response.status_code == 200:
16
  return response.json().get("response", "Error: Empty text data payload returned from server.")
17
  else:
18
  return f"⚠️ Kaggle server responded with error status: {response.status_code}\nDetails: {response.text}"
19
 
 
 
20
  except Exception as e:
21
- return f"🚨 Connection failed. Ensure your Kaggle notebook is running and active!\nError details: {str(e)}"
22
 
23
- # 📱 Wrap the Chat Interface in Blocks to set themes flawlessly across all Gradio builds
24
  with gr.Blocks(theme="soft") as demo:
25
  gr.ChatInterface(
26
  fn=chat_with_buddy,
 
5
  KAGGLE_BACKEND_URL = "https://gauchely-nonreconcilable-miracle.ngrok-free.dev"
6
 
7
  def chat_with_buddy(message, history):
 
8
  payload = {"prompt": message}
9
 
10
+ # 🛡️ BYPASS HEADERS: Tells Ngrok to skip the warning page and allow the connection straight through!
11
+ headers = {
12
+ "ngrok-skip-browser-warning": "true",
13
+ "User-Agent": "FlutterBuddyCustomClient/1.0"
14
+ }
15
+
16
  try:
17
+ # Fire the HTTP request directly over the web to your Kaggle dual-T4 GPUs with headers
18
+ response = requests.post(
19
+ f"{KAGGLE_BACKEND_URL}/generate",
20
+ json=payload,
21
+ headers=headers,
22
+ timeout=60 # Gives the model up to 60 seconds to process the handshake
23
+ )
24
 
25
  if response.status_code == 200:
26
  return response.json().get("response", "Error: Empty text data payload returned from server.")
27
  else:
28
  return f"⚠️ Kaggle server responded with error status: {response.status_code}\nDetails: {response.text}"
29
 
30
+ except gr.Error as ge:
31
+ raise ge
32
  except Exception as e:
33
+ return f"🚨 Connection failed. Ensure your Kaggle notebook cell is still running and hasn't timed out!\nError details: {str(e)}"
34
 
35
+ # 📱 Wrap the Chat Interface in Blocks to handle themes flawlessly across all Gradio builds
36
  with gr.Blocks(theme="soft") as demo:
37
  gr.ChatInterface(
38
  fn=chat_with_buddy,