singhina commited on
Commit
31b89f6
·
1 Parent(s): 7d4b8f7

Deploy Streamlit frontend with backend linkage

Browse files
Files changed (3) hide show
  1. huggingface.yml +2 -0
  2. requirements.txt +2 -2
  3. streamlit_app.py +47 -0
huggingface.yml ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ sdk: streamlit
2
+ app_file: streamlit_app.py
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
- altair
 
2
  pandas
3
- streamlit
 
1
+ streamlit
2
+ requests
3
  pandas
 
streamlit_app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests, pandas as pd
3
+
4
+ st.set_page_config(page_title="ExtraaLearn Lead Converter", layout="centered")
5
+ st.title("🎓 ExtraaLearn Lead Conversion")
6
+ st.write("Enter lead details and click Predict.")
7
+
8
+ # Input widgets
9
+ age = st.number_input("Age", 18, 100, 30)
10
+ visits = st.number_input("Website Visits", 0, 50, 1)
11
+ time_spent = st.number_input("Time Spent on Website (s)", 0, 5000, 300)
12
+ pages = st.number_input("Pages per Visit", 1, 20, 3)
13
+
14
+ occ = st.selectbox("Current Occupation", ["Professional","Unemployed","Student"])
15
+ first_int = st.selectbox("First Interaction", ["Website","Mobile App"])
16
+ profile = st.selectbox("Profile Completed", ["Low","Medium","High"])
17
+ print1 = st.checkbox("Saw Newspaper Ad")
18
+ print2 = st.checkbox("Saw Magazine Ad")
19
+ digital = st.checkbox("Saw Digital Ad")
20
+ edu_chan = st.checkbox("Heard via Education Channels")
21
+ referral = st.checkbox("Heard via Referral")
22
+ last_act = st.selectbox("Last Activity", ["Email Activity","Phone Activity","Website Activity"])
23
+
24
+ if st.button("Predict"):
25
+ payload = {
26
+ "age": age,
27
+ "website_visits": visits,
28
+ "time_spent_on_website": time_spent,
29
+ "page_views_per_visit": pages,
30
+ "current_occupation": occ,
31
+ "first_interaction": first_int,
32
+ "profile_completed": profile,
33
+ "print_media_type1": int(print1),
34
+ "print_media_type2": int(print2),
35
+ "digital_media": int(digital),
36
+ "educational_channels": int(edu_chan),
37
+ "referral": int(referral),
38
+ "last_activity": last_act
39
+ }
40
+ # Call the backend prediction endpoint
41
+ url = f"https://huggingface.co/spaces/{'"$BACKEND_REPO"'}'/predict"
42
+ resp = requests.post(url, json=payload)
43
+ if resp.ok:
44
+ res = resp.json()
45
+ st.success(f"Conversion: {res['prediction']} (Prob: {res['probability']:.2f})")
46
+ else:
47
+ st.error(f"Error {resp.status_code}: {resp.text}")