singhina commited on
Commit
e1da973
Β·
1 Parent(s): a9e9f21

Fix async loop via nest_asyncio and add to requirements

Browse files
Files changed (2) hide show
  1. app.py +8 -5
  2. requirements.txt +4 -3
app.py CHANGED
@@ -1,14 +1,18 @@
1
  import os
2
- # Redirect HOME so Streamlit can write config without root permission
3
  os.environ["HOME"] = "/tmp"
4
- # Disable usage stats to avoid writing to protected dirs
5
  os.environ["STREAMLIT_GATHER_USAGE_STATS"] = "false"
 
 
 
 
 
 
6
 
7
  import streamlit as st
8
  import requests
9
  import pandas as pd
10
 
11
- # Page config
12
  st.set_page_config(page_title="ExtraaLearn Lead Converter", layout="centered")
13
  st.title("πŸŽ“ ExtraaLearn Lead Conversion")
14
  st.write("Enter lead details and click Predict.")
@@ -45,8 +49,7 @@ if st.button("Predict"):
45
  "referral": int(referral),
46
  "last_activity": last_act
47
  }
48
- # Call the backend predict endpoint
49
- resp = requests.post("https://huggingface.co/spaces/singhina/ExtraaLeanBackend/predict", json=payload)
50
  if resp.ok:
51
  res = resp.json()
52
  st.success(f"Conversion: {res['prediction']} (Prob: {res['probability']:.2f})")
 
1
  import os
2
+ # Redirect HOME so Streamlit can write config without root permissions
3
  os.environ["HOME"] = "/tmp"
 
4
  os.environ["STREAMLIT_GATHER_USAGE_STATS"] = "false"
5
+ os.environ["STREAMLIT_CONFIG_DIR"] = "/tmp/.streamlit"
6
+ os.environ["STREAMLIT_CACHE_DIR"] = "/tmp/.streamlit"
7
+
8
+ # Patch asyncio event loop to avoid RuntimeError in Streamlit
9
+ import nest_asyncio
10
+ nest_asyncio.apply()
11
 
12
  import streamlit as st
13
  import requests
14
  import pandas as pd
15
 
 
16
  st.set_page_config(page_title="ExtraaLearn Lead Converter", layout="centered")
17
  st.title("πŸŽ“ ExtraaLearn Lead Conversion")
18
  st.write("Enter lead details and click Predict.")
 
49
  "referral": int(referral),
50
  "last_activity": last_act
51
  }
52
+ resp = requests.post("$BACKEND_URL", json=payload)
 
53
  if resp.ok:
54
  res = resp.json()
55
  st.success(f"Conversion: {res['prediction']} (Prob: {res['probability']:.2f})")
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
- streamlit
2
- requests
3
- pandas
 
 
1
+ streamlit>=1.0
2
+ nest_asyncio
3
+ requests>=2.0
4
+ pandas>=1.0