Sajjadistic commited on
Commit
cc0e613
·
verified ·
1 Parent(s): 39721f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -21
app.py CHANGED
@@ -6,49 +6,87 @@ import gradio as gr
6
  from analysis_core import extract_chats, get_chat_name, analyze_chat
7
 
8
 
9
- # -------------------- THEME --------------------
10
  THEME = gr.themes.Soft(
11
- primary_hue="fuchsia", # magenta / pink vibe
12
  secondary_hue="pink",
13
  neutral_hue="slate",
14
  )
15
 
16
  CSS = """
17
- /* make everything full width */
18
  .gradio-container {
19
  max-width: 100% !important;
20
  padding-left: 24px !important;
21
  padding-right: 24px !important;
22
  }
23
 
24
- /* Load button (magenta) */
25
  .btn-load button {
26
  background: linear-gradient(90deg, #d946ef, #ec4899) !important;
27
  border-radius: 16px !important;
28
  font-weight: 700 !important;
29
  }
30
-
31
- /* Analyze button (green, very clear action) */
32
  .btn-analyze button {
33
  background: linear-gradient(90deg, #22c55e, #16a34a) !important;
34
  border-radius: 16px !important;
35
  font-weight: 700 !important;
36
  }
37
 
38
- /* Status box nicer */
39
  .status-box textarea {
40
  border-radius: 14px !important;
41
  font-weight: 500;
42
  }
43
 
44
- /* Slightly larger plot */
45
- .plot-container {
46
- min-height: 520px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  }
48
  """
49
 
50
 
51
- # -------------------- HELPERS --------------------
52
  def _path(file_obj) -> str:
53
  if file_obj is None:
54
  raise gr.Error("upload Telegram result.json first.")
@@ -103,7 +141,6 @@ def run_analysis(choice: str, state: Dict[str, Any], max_bert_persian: int):
103
  return result, fig, pos_rows, neg_rows
104
 
105
 
106
- # -------------------- UI --------------------
107
  with gr.Blocks(
108
  title="Telegram Sentiment Analysis",
109
  theme=THEME,
@@ -142,15 +179,8 @@ with gr.Blocks(
142
  label="Max Persian messages to run BERT on (speed control)",
143
  )
144
 
145
- load_btn = gr.Button(
146
- "Load chats",
147
- elem_classes=["btn-load"],
148
- )
149
-
150
- analyze_btn = gr.Button(
151
- "Analyze selected chat",
152
- elem_classes=["btn-analyze"],
153
- )
154
 
155
  out_json = gr.JSON(label="Results (JSON)")
156
 
@@ -162,11 +192,13 @@ with gr.Blocks(
162
  out_pos = gr.Dataframe(
163
  label="Top 5 positive lex words (word, score)",
164
  headers=["word", "score"],
 
165
  )
166
 
167
  out_neg = gr.Dataframe(
168
  label="Top 5 negative lex words (word, score)",
169
  headers=["word", "score"],
 
170
  )
171
 
172
  load_btn.click(load_chats, inputs=[file_in], outputs=[chat_dd, state, status])
 
6
  from analysis_core import extract_chats, get_chat_name, analyze_chat
7
 
8
 
 
9
  THEME = gr.themes.Soft(
10
+ primary_hue="fuchsia",
11
  secondary_hue="pink",
12
  neutral_hue="slate",
13
  )
14
 
15
  CSS = """
16
+ /* full width */
17
  .gradio-container {
18
  max-width: 100% !important;
19
  padding-left: 24px !important;
20
  padding-right: 24px !important;
21
  }
22
 
23
+ /* buttons */
24
  .btn-load button {
25
  background: linear-gradient(90deg, #d946ef, #ec4899) !important;
26
  border-radius: 16px !important;
27
  font-weight: 700 !important;
28
  }
 
 
29
  .btn-analyze button {
30
  background: linear-gradient(90deg, #22c55e, #16a34a) !important;
31
  border-radius: 16px !important;
32
  font-weight: 700 !important;
33
  }
34
 
35
+ /* status */
36
  .status-box textarea {
37
  border-radius: 14px !important;
38
  font-weight: 500;
39
  }
40
 
41
+ /* plot */
42
+ .plot-container { min-height: 520px; }
43
+
44
+ /* -------- Dataframe styling (match magenta theme) -------- */
45
+ .lex-table .wrap {
46
+ border-radius: 16px !important;
47
+ border: 1px solid rgba(236,72,153,0.28) !important;
48
+ overflow: hidden !important;
49
+ }
50
+
51
+ .lex-table table {
52
+ border-collapse: separate !important;
53
+ border-spacing: 0 !important;
54
+ }
55
+
56
+ /* header */
57
+ .lex-table thead th {
58
+ background: linear-gradient(90deg, rgba(217,70,239,0.35), rgba(236,72,153,0.25)) !important;
59
+ color: rgba(255,255,255,0.92) !important;
60
+ font-weight: 800 !important;
61
+ border-bottom: 1px solid rgba(236,72,153,0.28) !important;
62
+ }
63
+
64
+ /* body cells */
65
+ .lex-table tbody td {
66
+ background: rgba(255,255,255,0.02) !important;
67
+ border-bottom: 1px solid rgba(236,72,153,0.10) !important;
68
+ }
69
+
70
+ /* zebra rows */
71
+ .lex-table tbody tr:nth-child(even) td {
72
+ background: rgba(217,70,239,0.06) !important;
73
+ }
74
+
75
+ /* hover */
76
+ .lex-table tbody tr:hover td {
77
+ background: rgba(236,72,153,0.14) !important;
78
+ }
79
+
80
+ /* align */
81
+ .lex-table td, .lex-table th { padding: 10px 12px !important; }
82
+
83
+ /* make numbers a bit clearer */
84
+ .lex-table td:last-child {
85
+ font-variant-numeric: tabular-nums;
86
  }
87
  """
88
 
89
 
 
90
  def _path(file_obj) -> str:
91
  if file_obj is None:
92
  raise gr.Error("upload Telegram result.json first.")
 
141
  return result, fig, pos_rows, neg_rows
142
 
143
 
 
144
  with gr.Blocks(
145
  title="Telegram Sentiment Analysis",
146
  theme=THEME,
 
179
  label="Max Persian messages to run BERT on (speed control)",
180
  )
181
 
182
+ load_btn = gr.Button("Load chats", elem_classes=["btn-load"])
183
+ analyze_btn = gr.Button("Analyze selected chat", elem_classes=["btn-analyze"])
 
 
 
 
 
 
 
184
 
185
  out_json = gr.JSON(label="Results (JSON)")
186
 
 
192
  out_pos = gr.Dataframe(
193
  label="Top 5 positive lex words (word, score)",
194
  headers=["word", "score"],
195
+ elem_classes=["lex-table"],
196
  )
197
 
198
  out_neg = gr.Dataframe(
199
  label="Top 5 negative lex words (word, score)",
200
  headers=["word", "score"],
201
+ elem_classes=["lex-table"],
202
  )
203
 
204
  load_btn.click(load_chats, inputs=[file_in], outputs=[chat_dd, state, status])