Spaces:
Sleeping
Sleeping
Final Fix: Removed local path checks
Browse files62 unmodified lines63646566676869707172737475767778798081828311 unmodified lines95969798991001011021031041051062 unmodified lines1091101111121131141151161171181191201211221237 unmodified lines13113213313413513613762 unmodified linesdf.to_csv(FEEDBACK_FILE, mode='a', header=False, index=False)# --- MODEL ENGINE PATH FIX ---# 1. This must be your EXACT Model Repo name from Screenshot 281MODEL_PATH = "SumedhGajbhiye/Sentiment-Analyzer"@st.cache_resourcedef load_engine():try:# We use the repo name directly.# Transformers will automatically download it if it's not local.return pipeline("sentiment-analysis", model=MODEL_PATH, tokenizer=MODEL_PATH)except Exception as e:st.error(f"Error loading model: {e}")return None# Remove or comment out any code that does:# if not os.path.exists(MODEL_PATH): st.error("Not found")# --- HEADER SECTION ---st.title("Sentiment Analyzer")11 unmodified linesst.info("Waiting for input...")# --- ANALYSIS INTERFACE ---# Check if model file exists locallyif not os.path.exists("model.safetensors"):st.error("System Core (model.safetensors) not found in directory!")else:classifier = load_engine(MODEL_PATH)user_input = st.text_input("QUERY INPUT:",placeholder="Enter sentence (English/Hindi/Hinglish)...",2 unmodified linesif user_input:with st.status("Neural Scan in Progress...", expanded=False) as status:result = classifier(user_input)[0]status.update(label="Analysis Complete", state="complete")label = result['label']score = result['score']# Adjust these keys to match your specific model's output labels (e.g., LABEL_0, LABEL_1)emoji_map = {"POSITIVE": "π’", "NEUTRAL": "π‘", "NEGATIVE": "π΄"}color = "#00ff88" if "POSITIVE" in label.upper() else "#ff4b4b" if "NEGATIVE" in label.upper() else "#ffaa00"st.markdown(f'''<div class="glass-card">7 unmodified linesfig = go.Figure(go.Indicator(mode = "gauge+number",value = score * 100,gauge = {'axis': {'range': [None, 100]}, 'bar': {'color': color}}))fig.update_layout(height=250, paper_bgcolor='rgba(0,0,0,0)', font={'color': "#fff"})st.plotly_chart(fig, use_container_width=True)62 unmodified lines6364656667686970717273747576777879808182838485868711 unmodified lines991001011021031041051061071081091102 unmodified lines1131141151161171181191201211221231241251261271281291307 unmodified lines13813914014114214314462 unmodified linesdf.to_csv(FEEDBACK_FILE, mode='a', header=False, index=False)# --- MODEL ENGINE PATH FIX ---import streamlit as stfrom transformers import pipeline# This MUST match your model repo name from Screenshot 281MODEL_REPO = "SumedhGajbhiye/Sentiment-Analyzer"@st.cache_resourcedef load_analysis_engine():try:# This tells the app to download weights from the Hub, not the local folderreturn pipeline("sentiment-analysis", model=MODEL_REPO, tokenizer=MODEL_REPO)except Exception as e:st.error(f"Could not connect to System Core: {e}")return None# IMPORTANT: Find and delete the line in your code that says:# if not os.path.exists("model.safetensors"): st.error("System Core... not found")# --- HEADER SECTION ---st.title("Sentiment Analyzer")11 unmodified linesst.info("Waiting for input...")# --- ANALYSIS INTERFACE ---# 1. We call the cached loader (it handles the Hub download automatically)classifier = load_analysis_engine()if classifier is None:st.error("System Core could not be initialized. Please check the logs.")else:user_input = st.text_input("QUERY INPUT:",placeholder="Enter sentence (English/Hindi/Hinglish)...",2 unmodified linesif user_input:with st.status("Neural Scan in Progress...", expanded=False) as status:# Running the inferenceresult = classifier(user_input)[0]status.update(label="Analysis Complete", state="complete")label = result['label']score = result['score']# Mapping labels (Adjust if your XLM-Roberta uses LABEL_0/1/2)emoji_map = {"POSITIVE": "π’", "NEUTRAL": "π‘", "NEGATIVE": "π΄"}# Color logiccolor = "#00ff88" if "POS" in label.upper() else "#ff4b4b" if "NEG" in label.upper() else "#ffaa00"st.markdown(f'''<div class="glass-card">7 unmodified linesfig = go.Figure(go.Indicator(mode = "gauge+number",value = score * 100,gauge = {'axis': {'range': [0, 100]}, 'bar': {'color': color}}))fig.update_layout(height=250, paper_bgcolor='rgba(0,0,0,0)', font={'color': "#fff"})st.plotly_chart(fig, use_container_width=True)
src/streamlit_app.py+24-17