bankai-007 commited on
Commit
58f2731
·
verified ·
1 Parent(s): d27e581

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +30 -51
src/streamlit_app.py CHANGED
@@ -8,65 +8,43 @@ import time
8
  # --- UI CONFIGURATION ---
9
  st.set_page_config(page_title="NEURAL-X | AI Classifier", layout="wide", initial_sidebar_state="expanded")
10
 
11
- # --- CUSTOM CSS (The Secret Sauce) ---
12
  st.markdown("""
13
  <style>
14
- /* Main Background */
15
- .stApp {
16
- background: radial-gradient(circle at top right, #1e293b, #0f172a);
17
- color: #f8fafc;
18
- }
19
 
20
- /* Header Styling */
21
- h1 {
22
- font-family: 'Inter', sans-serif;
23
- font-weight: 800;
24
- background: -webkit-linear-gradient(#38bdf8, #818cf8);
25
- -webkit-background-clip: text;
26
- -webkit-text-fill-color: transparent;
27
- letter-spacing: -1px;
28
  }
29
-
30
- /* Glassmorphism Cards */
31
- div[data-testid="stVerticalBlock"] > div:has(div.stTextArea) {
32
- background: rgba(255, 255, 255, 0.03);
33
- padding: 2rem;
34
- border-radius: 20px;
35
- border: 1px solid rgba(255, 255, 255, 0.1);
36
  backdrop-filter: blur(10px);
37
  }
 
38
 
39
- /* Button Styling */
40
- .stButton > button {
41
- width: 100%;
42
- background: linear-gradient(90deg, #6366f1 0%, #a855f7 100%);
43
- color: white;
44
- border: none;
45
- padding: 0.75rem;
46
- border-radius: 12px;
47
- font-weight: 600;
48
- transition: all 0.3s ease;
49
- text-transform: uppercase;
50
- letter-spacing: 1px;
51
- }
52
- .stButton > button:hover {
53
- transform: translateY(-2px);
54
- box-shadow: 0 10px 20px rgba(99, 102, 241, 0.4);
55
- }
56
-
57
- /* Result Metric Styling */
58
- [data-testid="stMetricValue"] {
59
- color: #38bdf8;
60
- font-size: 2.5rem !important;
61
  }
 
 
 
62
  </style>
63
  """, unsafe_allow_html=True)
64
 
65
  # --- AI BACKEND ---
66
  @st.cache_resource(show_spinner=False)
67
  def load_ai():
68
- device = 0 if torch.cuda.is_available() else -1
69
- return pipeline("zero-shot-classification", model="facebook/bart-large-mnli", device=device)
70
 
71
  classifier = load_ai()
72
 
@@ -94,31 +72,30 @@ st.write("#### Enterprise-grade semantic analysis powered by Deep Learning.")
94
  col1, col2 = st.columns([1.2, 0.8], gap="large")
95
 
96
  with col1:
97
- text_input = st.text_area("INPUT STREAM", height=250, placeholder="Paste raw text, news articles, or transcripts here...")
98
  analyze_btn = st.button("Execute Neural Scan")
99
 
100
  with col2:
101
  if analyze_btn:
102
  if not text_input.strip():
103
- st.warning("⚠️ Neural input buffer empty. Please provide text.")
104
  else:
105
  with st.spinner("Processing Tensors..."):
106
  start_time = time.time()
107
  result = classifier(text_input, HIDDEN_LABELS, multi_label=True)
108
  end_time = time.time()
109
 
110
- # Dynamic Logic
111
  valid_pairs = [(l, s) for l, s in zip(result['labels'], result['scores']) if s >= 0.60]
112
  if not valid_pairs:
113
  valid_pairs = [(result['labels'][0], result['scores'][0])]
114
 
115
- # Metrics
116
  st.subheader("Analysis Results")
117
  m1, m2 = st.columns(2)
 
 
118
  m1.metric("Top Category", valid_pairs[0][0])
119
  m2.metric("Inference Time", f"{round(end_time - start_time, 2)}s")
120
 
121
- # Chart
122
  df = pd.DataFrame({
123
  "Concept": [p[0] for p in valid_pairs],
124
  "Confidence": [p[1] for p in valid_pairs]
@@ -127,10 +104,12 @@ with col2:
127
  fig = px.bar(df, x="Confidence", y="Concept", orientation='h',
128
  color="Confidence", color_continuous_scale="Tealgrn",
129
  template="plotly_dark")
 
 
 
130
  fig.update_layout(paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)')
131
  st.plotly_chart(fig, use_container_width=True)
132
 
133
- # Add to History
134
  st.session_state.history.append({"label": valid_pairs[0][0], "text": text_input})
135
  else:
136
  st.info("💡 Enter text and initiate scan to view semantic mapping.")
 
8
  # --- UI CONFIGURATION ---
9
  st.set_page_config(page_title="NEURAL-X | AI Classifier", layout="wide", initial_sidebar_state="expanded")
10
 
11
+ # --- CUSTOM CSS ---
12
  st.markdown("""
13
  <style>
14
+ .stApp { background: radial-gradient(circle at top right, #1e293b, #0f172a); color: #f8fafc; }
15
+ h1 { font-family: 'Inter', sans-serif; font-weight: 800; background: -webkit-linear-gradient(#38bdf8, #818cf8); -webkit-background-clip: text; -webkit-text-fill-color: transparent; letter-spacing: -1px; }
 
 
 
16
 
17
+ /* FIX 1: STOP TEXT AREA OVERFLOW */
18
+ div.stTextArea {
19
+ width: 100% !important;
20
+ box-sizing: border-box !important;
 
 
 
 
21
  }
22
+ div[data-baseweb="textarea"] {
23
+ background: rgba(255, 255, 255, 0.03) !important;
24
+ border: 1px solid rgba(255, 255, 255, 0.1) !important;
25
+ border-radius: 15px !important;
 
 
 
26
  backdrop-filter: blur(10px);
27
  }
28
+ textarea { color: white !important; }
29
 
30
+ /* FIX 2: FORCE FULL LABEL NAMES TO WRAP, NOT TRUNCATE */
31
+ [data-testid="stMetricValue"] {
32
+ color: #38bdf8;
33
+ font-size: 2rem !important;
34
+ white-space: normal !important;
35
+ word-wrap: break-word !important;
36
+ line-height: 1.2;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  }
38
+
39
+ .stButton > button { width: 100%; background: linear-gradient(90deg, #6366f1 0%, #a855f7 100%); color: white; border: none; padding: 0.75rem; border-radius: 12px; font-weight: 600; transition: all 0.3s ease; text-transform: uppercase; letter-spacing: 1px; }
40
+ .stButton > button:hover { transform: translateY(-2px); box-shadow: 0 10px 20px rgba(99, 102, 241, 0.4); }
41
  </style>
42
  """, unsafe_allow_html=True)
43
 
44
  # --- AI BACKEND ---
45
  @st.cache_resource(show_spinner=False)
46
  def load_ai():
47
+ return pipeline("zero-shot-classification", model="cross-encoder/nli-distilroberta-base", device=-1)
 
48
 
49
  classifier = load_ai()
50
 
 
72
  col1, col2 = st.columns([1.2, 0.8], gap="large")
73
 
74
  with col1:
75
+ text_input = st.text_area("INPUT STREAM", height=250, placeholder="Paste raw text here...")
76
  analyze_btn = st.button("Execute Neural Scan")
77
 
78
  with col2:
79
  if analyze_btn:
80
  if not text_input.strip():
81
+ st.warning("⚠️ Neural input buffer empty.")
82
  else:
83
  with st.spinner("Processing Tensors..."):
84
  start_time = time.time()
85
  result = classifier(text_input, HIDDEN_LABELS, multi_label=True)
86
  end_time = time.time()
87
 
 
88
  valid_pairs = [(l, s) for l, s in zip(result['labels'], result['scores']) if s >= 0.60]
89
  if not valid_pairs:
90
  valid_pairs = [(result['labels'][0], result['scores'][0])]
91
 
 
92
  st.subheader("Analysis Results")
93
  m1, m2 = st.columns(2)
94
+
95
+ # Metric will now properly wrap text instead of "..."
96
  m1.metric("Top Category", valid_pairs[0][0])
97
  m2.metric("Inference Time", f"{round(end_time - start_time, 2)}s")
98
 
 
99
  df = pd.DataFrame({
100
  "Concept": [p[0] for p in valid_pairs],
101
  "Confidence": [p[1] for p in valid_pairs]
 
104
  fig = px.bar(df, x="Confidence", y="Concept", orientation='h',
105
  color="Confidence", color_continuous_scale="Tealgrn",
106
  template="plotly_dark")
107
+
108
+ # FIX 3: Force Plotly to give long labels enough margin space
109
+ fig.update_yaxes(automargin=True)
110
  fig.update_layout(paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)')
111
  st.plotly_chart(fig, use_container_width=True)
112
 
 
113
  st.session_state.history.append({"label": valid_pairs[0][0], "text": text_input})
114
  else:
115
  st.info("💡 Enter text and initiate scan to view semantic mapping.")