Spaces:
Running
Running
| import streamlit as st | |
| from shared.hf_helpers import build_pipeline | |
| from retailgpt_evaluator.leaderboard import build_leaderboard | |
| import yaml, pandas as pd, os | |
| from pathlib import Path | |
| def main(): | |
| # Safely set page config (wonβt error inside streamlit_hub.py) | |
| try: | |
| st.set_page_config(page_title="RetailGPT Evaluator", page_icon="ποΈ", layout="wide") | |
| except st.errors.StreamlitAPIException: | |
| pass | |
| st.title("ποΈ RetailGPT Evaluator β AxionX Digital") | |
| # Load config safely | |
| config_path = Path(__file__).resolve().parent / "config.yaml" | |
| with open(config_path) as f: | |
| cfg = yaml.safe_load(f) | |
| # Show leaderboard if exists | |
| if os.path.exists("models/retail_eval_results.json"): | |
| df = build_leaderboard() | |
| st.subheader("π Model Leaderboard") | |
| st.dataframe(df, use_container_width=True) | |
| else: | |
| st.warning("Run `evaluate.py` first to generate metrics.") | |
| # Model chat interface | |
| st.markdown("---") | |
| model_name = st.selectbox("Choose a model to chat with:", cfg["models"]) | |
| pipe = build_pipeline(model_name) | |
| query = st.text_area("Customer query:", "Which is the best country for retail?.") | |
| if st.button("Ask Model"): | |
| result = pipe(query, max_new_tokens=cfg["demo"]["max_new_tokens"]) | |
| st.markdown("### π§ Model Response") | |
| st.write(result[0]["generated_text"]) | |
| # Ensure it's import-safe | |
| if __name__ == "__main__": | |
| main() | |