Spaces:
Sleeping
Sleeping
Final Fix: Removed local path checks
Browse files- src/streamlit_app.py +24 -17
src/streamlit_app.py
CHANGED
|
@@ -63,21 +63,25 @@ def save_smart_data(text, ai_label, ai_score, corrected_label=None):
|
|
| 63 |
df.to_csv(FEEDBACK_FILE, mode='a', header=False, index=False)
|
| 64 |
|
| 65 |
# --- MODEL ENGINE PATH FIX ---
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
@st.cache_resource
|
| 70 |
-
def
|
| 71 |
try:
|
| 72 |
-
#
|
| 73 |
-
|
| 74 |
-
return pipeline("sentiment-analysis", model=MODEL_PATH, tokenizer=MODEL_PATH)
|
| 75 |
except Exception as e:
|
| 76 |
-
st.error(f"
|
| 77 |
return None
|
| 78 |
|
| 79 |
-
#
|
| 80 |
-
# if not os.path.exists(
|
|
|
|
|
|
|
| 81 |
|
| 82 |
# --- HEADER SECTION ---
|
| 83 |
st.title("Sentiment Analyzer")
|
|
@@ -95,12 +99,12 @@ with st.sidebar:
|
|
| 95 |
st.info("Waiting for input...")
|
| 96 |
|
| 97 |
# --- ANALYSIS INTERFACE ---
|
| 98 |
-
#
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
| 101 |
else:
|
| 102 |
-
classifier = load_engine(MODEL_PATH)
|
| 103 |
-
|
| 104 |
user_input = st.text_input(
|
| 105 |
"QUERY INPUT:",
|
| 106 |
placeholder="Enter sentence (English/Hindi/Hinglish)...",
|
|
@@ -109,15 +113,18 @@ else:
|
|
| 109 |
|
| 110 |
if user_input:
|
| 111 |
with st.status("Neural Scan in Progress...", expanded=False) as status:
|
|
|
|
| 112 |
result = classifier(user_input)[0]
|
| 113 |
status.update(label="Analysis Complete", state="complete")
|
| 114 |
|
| 115 |
label = result['label']
|
| 116 |
score = result['score']
|
| 117 |
|
| 118 |
-
#
|
| 119 |
emoji_map = {"POSITIVE": "π’", "NEUTRAL": "π‘", "NEGATIVE": "π΄"}
|
| 120 |
-
|
|
|
|
|
|
|
| 121 |
|
| 122 |
st.markdown(f'''
|
| 123 |
<div class="glass-card">
|
|
@@ -131,7 +138,7 @@ else:
|
|
| 131 |
fig = go.Figure(go.Indicator(
|
| 132 |
mode = "gauge+number",
|
| 133 |
value = score * 100,
|
| 134 |
-
gauge = {'axis': {'range': [
|
| 135 |
))
|
| 136 |
fig.update_layout(height=250, paper_bgcolor='rgba(0,0,0,0)', font={'color': "#fff"})
|
| 137 |
st.plotly_chart(fig, use_container_width=True)
|
|
|
|
| 63 |
df.to_csv(FEEDBACK_FILE, mode='a', header=False, index=False)
|
| 64 |
|
| 65 |
# --- MODEL ENGINE PATH FIX ---
|
| 66 |
+
import streamlit as st
|
| 67 |
+
from transformers import pipeline
|
| 68 |
+
|
| 69 |
+
# This MUST match your model repo name from Screenshot 281
|
| 70 |
+
MODEL_REPO = "SumedhGajbhiye/Sentiment-Analyzer"
|
| 71 |
|
| 72 |
@st.cache_resource
|
| 73 |
+
def load_analysis_engine():
|
| 74 |
try:
|
| 75 |
+
# This tells the app to download weights from the Hub, not the local folder
|
| 76 |
+
return pipeline("sentiment-analysis", model=MODEL_REPO, tokenizer=MODEL_REPO)
|
|
|
|
| 77 |
except Exception as e:
|
| 78 |
+
st.error(f"Could not connect to System Core: {e}")
|
| 79 |
return None
|
| 80 |
|
| 81 |
+
# IMPORTANT: Find and delete the line in your code that says:
|
| 82 |
+
# if not os.path.exists("model.safetensors"): st.error("System Core... not found")
|
| 83 |
+
|
| 84 |
+
|
| 85 |
|
| 86 |
# --- HEADER SECTION ---
|
| 87 |
st.title("Sentiment Analyzer")
|
|
|
|
| 99 |
st.info("Waiting for input...")
|
| 100 |
|
| 101 |
# --- ANALYSIS INTERFACE ---
|
| 102 |
+
# 1. We call the cached loader (it handles the Hub download automatically)
|
| 103 |
+
classifier = load_analysis_engine()
|
| 104 |
+
|
| 105 |
+
if classifier is None:
|
| 106 |
+
st.error("System Core could not be initialized. Please check the logs.")
|
| 107 |
else:
|
|
|
|
|
|
|
| 108 |
user_input = st.text_input(
|
| 109 |
"QUERY INPUT:",
|
| 110 |
placeholder="Enter sentence (English/Hindi/Hinglish)...",
|
|
|
|
| 113 |
|
| 114 |
if user_input:
|
| 115 |
with st.status("Neural Scan in Progress...", expanded=False) as status:
|
| 116 |
+
# Running the inference
|
| 117 |
result = classifier(user_input)[0]
|
| 118 |
status.update(label="Analysis Complete", state="complete")
|
| 119 |
|
| 120 |
label = result['label']
|
| 121 |
score = result['score']
|
| 122 |
|
| 123 |
+
# Mapping labels (Adjust if your XLM-Roberta uses LABEL_0/1/2)
|
| 124 |
emoji_map = {"POSITIVE": "π’", "NEUTRAL": "π‘", "NEGATIVE": "π΄"}
|
| 125 |
+
|
| 126 |
+
# Color logic
|
| 127 |
+
color = "#00ff88" if "POS" in label.upper() else "#ff4b4b" if "NEG" in label.upper() else "#ffaa00"
|
| 128 |
|
| 129 |
st.markdown(f'''
|
| 130 |
<div class="glass-card">
|
|
|
|
| 138 |
fig = go.Figure(go.Indicator(
|
| 139 |
mode = "gauge+number",
|
| 140 |
value = score * 100,
|
| 141 |
+
gauge = {'axis': {'range': [0, 100]}, 'bar': {'color': color}}
|
| 142 |
))
|
| 143 |
fig.update_layout(height=250, paper_bgcolor='rgba(0,0,0,0)', font={'color': "#fff"})
|
| 144 |
st.plotly_chart(fig, use_container_width=True)
|