Ginidu2003 commited on
Commit
24d4d93
Β·
verified Β·
1 Parent(s): deac599

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -32
app.py CHANGED
@@ -28,7 +28,7 @@ def preprocess_text(text):
28
 
29
  classifier_model = "Ginidu2003/Distilbert-Base-News-classifier"
30
 
31
- # ====================== COLORED BAR CHART ======================
32
  def create_colored_bar_chart(category_counts):
33
  if category_counts is None or len(category_counts) == 0:
34
  fig, ax = plt.subplots()
@@ -38,17 +38,19 @@ def create_colored_bar_chart(category_counts):
38
  categories = category_counts["Category"]
39
  counts = category_counts["Count"]
40
 
41
- colors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEEAD']
 
42
 
43
- fig, ax = plt.subplots(figsize=(10, 6))
44
- bars = ax.bar(categories, counts, color=colors)
45
 
 
46
  for bar in bars:
47
  height = bar.get_height()
48
- ax.text(bar.get_x() + bar.get_width()/2, height + 0.5,
49
- str(int(height)), ha='center', va='bottom', fontsize=12, fontweight='bold')
50
 
51
- ax.set_title("Category Distribution Across 5 Classes", fontsize=16, fontweight='bold')
52
  ax.set_xlabel("Category", fontsize=12)
53
  ax.set_ylabel("Count", fontsize=12)
54
  plt.xticks(rotation=15)
@@ -116,14 +118,25 @@ def answer_question(news_content, question):
116
  except Exception as e:
117
  return f"Error: {str(e)}"
118
 
119
- # ====================== BEAUTIFUL GRADIO INTERFACE ======================
120
  with gr.Blocks(
121
  title="English News Classifier",
122
- theme=gr.themes.Soft(), # Beautiful modern theme
123
  css="""
124
- .gradio-container {max-width: 1100px; margin: auto;}
125
- h1 {font-size: 2.5rem; text-align: center;}
126
- .tab-label {font-size: 1.1rem; font-weight: 600;}
 
 
 
 
 
 
 
 
 
 
 
127
  """
128
  ) as demo:
129
 
@@ -131,16 +144,14 @@ with gr.Blocks(
131
  gr.Markdown("### Intelligent News Analysis Tool | Daily Mirror Sri Lanka")
132
 
133
  with gr.Tabs():
134
- # ====================== CLASSIFICATION TAB ======================
135
  with gr.Tab("πŸ“Š News Classification"):
136
  gr.Markdown("### Upload CSV and get automatic category prediction")
137
 
138
- with gr.Row():
139
- file_input = gr.File(
140
- label="πŸ“€ Upload your CSV file",
141
- file_types=[".csv"],
142
- height=120
143
- )
144
 
145
  classify_btn = gr.Button("πŸš€ Classify News", variant="primary", size="large")
146
 
@@ -156,20 +167,10 @@ with gr.Blocks(
156
  outputs=[output_text, output_file, bar_chart]
157
  )
158
 
159
- # ====================== Q&A TAB ======================
160
  with gr.Tab("❓ Question Answering"):
161
  gr.Markdown("### Ask any question about a news article")
162
-
163
- news_input = gr.Textbox(
164
- lines=10,
165
- label="πŸ“ Paste News Content",
166
- placeholder="Paste the full news article here..."
167
- )
168
- question_input = gr.Textbox(
169
- label="❓ Your Question",
170
- placeholder="e.g., What is the main issue? Who is involved?"
171
- )
172
-
173
  qa_btn = gr.Button("πŸ” Get Answer", variant="primary", size="large")
174
  qa_output = gr.Textbox(label="πŸ’‘ Answer", lines=6)
175
 
@@ -180,6 +181,6 @@ with gr.Blocks(
180
  )
181
 
182
  gr.Markdown("---")
183
- gr.Markdown("**Built for Text Analytics Assignment (In23-S5-DA3111) - Section 02**")
184
 
185
  demo.launch()
 
28
 
29
  classifier_model = "Ginidu2003/Distilbert-Base-News-classifier"
30
 
31
+ # ====================== BEAUTIFUL COLORED BAR CHART ======================
32
  def create_colored_bar_chart(category_counts):
33
  if category_counts is None or len(category_counts) == 0:
34
  fig, ax = plt.subplots()
 
38
  categories = category_counts["Category"]
39
  counts = category_counts["Count"]
40
 
41
+ # Nice modern color palette
42
+ colors = ['#3498DB', '#E67E22', '#9B59B6', '#2ECC71', '#E74C3C']
43
 
44
+ fig, ax = plt.subplots(figsize=(11, 6))
45
+ bars = ax.bar(categories, counts, color=colors, edgecolor='white', linewidth=0.8)
46
 
47
+ # Add value on top of bars
48
  for bar in bars:
49
  height = bar.get_height()
50
+ ax.text(bar.get_x() + bar.get_width()/2, height + 0.8,
51
+ str(int(height)), ha='center', va='bottom', fontsize=13, fontweight='bold')
52
 
53
+ ax.set_title("Category Distribution Across 5 Classes", fontsize=16, fontweight='bold', pad=20)
54
  ax.set_xlabel("Category", fontsize=12)
55
  ax.set_ylabel("Count", fontsize=12)
56
  plt.xticks(rotation=15)
 
118
  except Exception as e:
119
  return f"Error: {str(e)}"
120
 
121
+ # ====================== BEAUTIFUL UI ======================
122
  with gr.Blocks(
123
  title="English News Classifier",
124
+ theme=gr.themes.Dark(),
125
  css="""
126
+ .gradio-container {
127
+ max-width: 1200px;
128
+ margin: auto;
129
+ background: linear-gradient(180deg, #1a1a2e, #16213e);
130
+ }
131
+ h1 {
132
+ text-align: center;
133
+ font-size: 2.8rem;
134
+ margin-bottom: 10px;
135
+ }
136
+ .tab-label {
137
+ font-size: 1.2rem;
138
+ font-weight: 600;
139
+ }
140
  """
141
  ) as demo:
142
 
 
144
  gr.Markdown("### Intelligent News Analysis Tool | Daily Mirror Sri Lanka")
145
 
146
  with gr.Tabs():
 
147
  with gr.Tab("πŸ“Š News Classification"):
148
  gr.Markdown("### Upload CSV and get automatic category prediction")
149
 
150
+ file_input = gr.File(
151
+ label="πŸ“€ Upload your CSV file",
152
+ file_types=[".csv"],
153
+ height=140
154
+ )
 
155
 
156
  classify_btn = gr.Button("πŸš€ Classify News", variant="primary", size="large")
157
 
 
167
  outputs=[output_text, output_file, bar_chart]
168
  )
169
 
 
170
  with gr.Tab("❓ Question Answering"):
171
  gr.Markdown("### Ask any question about a news article")
172
+ news_input = gr.Textbox(lines=12, label="πŸ“ Paste News Content", placeholder="Paste the full news article here...")
173
+ question_input = gr.Textbox(label="❓ Your Question", placeholder="e.g. What is the main topic?")
 
 
 
 
 
 
 
 
 
174
  qa_btn = gr.Button("πŸ” Get Answer", variant="primary", size="large")
175
  qa_output = gr.Textbox(label="πŸ’‘ Answer", lines=6)
176
 
 
181
  )
182
 
183
  gr.Markdown("---")
184
+ gr.Markdown("**Built for Text Analytics Assignment - Section 02**")
185
 
186
  demo.launch()