deepsodha commited on
Commit
c2c7976
Β·
verified Β·
1 Parent(s): 0de700e

Update retailgpt_evaluator/app.py

Browse files
Files changed (1) hide show
  1. retailgpt_evaluator/app.py +33 -48
retailgpt_evaluator/app.py CHANGED
@@ -2,56 +2,41 @@ import streamlit as st
2
  from shared.hf_helpers import build_pipeline
3
  from retailgpt_evaluator.leaderboard import build_leaderboard
4
  import yaml, pandas as pd, os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- # βœ… Safe config β€” only runs if not already set by hub
7
- try:
8
- st.set_page_config(page_title="RetailGPT Evaluator", page_icon="πŸ›οΈ", layout="wide")
9
- except st.errors.StreamlitAPIException:
10
- pass # Already configured by main Streamlit Hub
11
-
12
- # -------------------------------
13
- # Title & Description
14
- # -------------------------------
15
- st.title("πŸ›οΈ RetailGPT Evaluator β€” AxionX Digital")
16
- st.write("Benchmark and chat with multiple retail QA models.")
17
-
18
- # -------------------------------
19
- # Load Configuration
20
- # -------------------------------
21
- with open("retailgpt_evaluator/config.yaml") as f:
22
- cfg = yaml.safe_load(f)
23
-
24
- # -------------------------------
25
- # Leaderboard Section
26
- # -------------------------------
27
- if os.path.exists("models/retail_eval_results.json"):
28
- df = build_leaderboard()
29
- st.subheader("πŸ“Š Model Leaderboard")
30
- st.dataframe(df, use_container_width=True)
31
- else:
32
- st.warning("Run `evaluate.py` first to generate metrics.")
33
-
34
- # -------------------------------
35
- # Chat Interface
36
- # -------------------------------
37
- st.markdown("---")
38
- st.subheader("πŸ’¬ Chat With a Model")
39
-
40
- model_name = st.selectbox("Choose a model to chat with:", cfg["models"])
41
- pipe = build_pipeline(model_name)
42
 
43
- query = st.text_area("Customer query:", "I want to return a damaged product.")
44
- if st.button("Ask Model"):
45
- if query.strip():
46
- with st.spinner("Generating response..."):
47
- result = pipe(query, max_new_tokens=cfg["demo"]["max_new_tokens"])
48
  st.markdown("### 🧠 Model Response")
49
  st.write(result[0]["generated_text"])
50
- else:
51
- st.warning("Please enter a customer query above before submitting.")
52
 
53
- # -------------------------------
54
- # Footer
55
- # -------------------------------
56
- st.markdown("---")
57
- st.caption("Β© 2025 AxionX Digital β€” Innovating Tomorrow")
 
2
  from shared.hf_helpers import build_pipeline
3
  from retailgpt_evaluator.leaderboard import build_leaderboard
4
  import yaml, pandas as pd, os
5
+ from pathlib import Path
6
+
7
+ def main():
8
+ # Safely set page config (won’t error inside streamlit_hub.py)
9
+ try:
10
+ st.set_page_config(page_title="RetailGPT Evaluator", page_icon="πŸ›οΈ", layout="wide")
11
+ except st.errors.StreamlitAPIException:
12
+ pass
13
+
14
+ st.title("πŸ›οΈ RetailGPT Evaluator β€” AxionX Digital")
15
+
16
+ # Load config safely
17
+ config_path = Path(__file__).resolve().parent / "config.yaml"
18
+ with open(config_path) as f:
19
+ cfg = yaml.safe_load(f)
20
+
21
+ # Show leaderboard if exists
22
+ if os.path.exists("models/retail_eval_results.json"):
23
+ df = build_leaderboard()
24
+ st.subheader("πŸ“Š Model Leaderboard")
25
+ st.dataframe(df, use_container_width=True)
26
+ else:
27
+ st.warning("Run `evaluate.py` first to generate metrics.")
28
 
29
+ # Model chat interface
30
+ st.markdown("---")
31
+ model_name = st.selectbox("Choose a model to chat with:", cfg["models"])
32
+ pipe = build_pipeline(model_name)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
+ query = st.text_area("Customer query:", "I want to return a damaged product.")
35
+ if st.button("Ask Model"):
36
+ result = pipe(query, max_new_tokens=cfg["demo"]["max_new_tokens"])
 
 
37
  st.markdown("### 🧠 Model Response")
38
  st.write(result[0]["generated_text"])
 
 
39
 
40
+ # Ensure it's import-safe
41
+ if __name__ == "__main__":
42
+ main()