AJC1 commited on
Commit
f7c2aac
·
verified ·
1 Parent(s): bb48108

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -4,21 +4,20 @@ import torch
4
  import pandas as pd
5
  import os
6
 
7
- # --- Configuration ---
8
- # Use your verified public model path
9
- MODEL_HUB_PATH = "AJC1/ag_news_distilbert_finetuned"
10
- TARGET_NAMES = ["World", "Sports", "Business", "Sci/Tech"]
11
 
12
- # --- 1. Load Model (Cached for performance) ---
13
  try:
14
- tokenizer = AutoTokenizer.from_pretrained(MODEL_HUB_PATH)
15
- model = AutoModelForSequenceClassification.from_pretrained(MODEL_HUB_PATH)
16
  model.eval()
17
  print("Model loaded successfully.")
18
  except Exception as e:
19
  print(f"Error loading model: {e}")
20
 
21
- # --- 2. Prediction Functions ---
22
 
23
  def predict_single_text(text):
24
  """The core logic: text -> dict of scores"""
@@ -48,7 +47,7 @@ def process_csv_file(file_obj):
48
  if not target_col:
49
  target_col = df.columns[0] # Fallback to first column
50
 
51
- # Run predictions (Iterating for safety, batching could be faster but more complex)
52
  predicted_labels = []
53
  confidence_scores = []
54
 
@@ -72,15 +71,15 @@ def process_csv_file(file_obj):
72
  except Exception as e:
73
  return None, f"Error processing file: {str(e)}"
74
 
75
- # --- 3. The Professional Tabbed Interface ---
76
  with gr.Blocks(title="AG News Enterprise Classifier") as demo:
77
 
78
- gr.Markdown("# 📰 Automated News Routing System")
79
  gr.Markdown("Select a workflow below: Single-item checking or Bulk file processing.")
80
 
81
  with gr.Tabs():
82
 
83
- # === TAB 1: Single Input (For Demo/Editors) ===
84
  with gr.TabItem("Live Check"):
85
  with gr.Row():
86
  with gr.Column():
@@ -103,7 +102,7 @@ with gr.Blocks(title="AG News Enterprise Classifier") as demo:
103
  inputs=text_input
104
  )
105
 
106
- # === TAB 2: Batch Processing (For Operations) ===
107
  with gr.TabItem("Bulk Analysis (CSV)"):
108
  gr.Markdown("Upload a CSV file containing news headlines. The system will append a 'Category' column and return the file.")
109
 
 
4
  import pandas as pd
5
  import os
6
 
7
+ # Public model path
8
+ model_hub_path = "AJC1/ag_news_distilbert_finetuned"
9
+ target_names = ["World", "Sports", "Business", "Sci/Tech"]
 
10
 
11
+ # Load Model
12
  try:
13
+ tokenizer = AutoTokenizer.from_pretrained(model_hub_path)
14
+ model = AutoModelForSequenceClassification.from_pretrained(model_hub_path)
15
  model.eval()
16
  print("Model loaded successfully.")
17
  except Exception as e:
18
  print(f"Error loading model: {e}")
19
 
20
+ # Prediction Functions
21
 
22
  def predict_single_text(text):
23
  """The core logic: text -> dict of scores"""
 
47
  if not target_col:
48
  target_col = df.columns[0] # Fallback to first column
49
 
50
+ # Run predictions
51
  predicted_labels = []
52
  confidence_scores = []
53
 
 
71
  except Exception as e:
72
  return None, f"Error processing file: {str(e)}"
73
 
74
+ # The Professional Tabbed Interface
75
  with gr.Blocks(title="AG News Enterprise Classifier") as demo:
76
 
77
+ gr.Markdown("#Automated News Routing System")
78
  gr.Markdown("Select a workflow below: Single-item checking or Bulk file processing.")
79
 
80
  with gr.Tabs():
81
 
82
+ # TAB 1: Single Input
83
  with gr.TabItem("Live Check"):
84
  with gr.Row():
85
  with gr.Column():
 
102
  inputs=text_input
103
  )
104
 
105
+ # TAB 2: Batch Processing
106
  with gr.TabItem("Bulk Analysis (CSV)"):
107
  gr.Markdown("Upload a CSV file containing news headlines. The system will append a 'Category' column and return the file.")
108