VoltIC commited on
Commit
68173c2
Β·
verified Β·
1 Parent(s): 4303a27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -9
app.py CHANGED
@@ -1,17 +1,21 @@
1
  import gradio as gr
2
- from transformers import pipeline, BartForConditionalGeneration, BartTokenizer
3
  import torch
4
 
5
  # 1. Configuration
6
  MODEL_ID = "VoltIC/Automated-Text-Summarizer"
7
  SUBFOLDER = "summarizer_model"
8
 
9
- print("πŸš€ Phase 1: Loading BART-specific Tokenizer...")
10
- # We use BartTokenizer directly to bypass the config.json check
11
- tokenizer = BartTokenizer.from_pretrained(MODEL_ID, subfolder=SUBFOLDER)
 
 
 
 
12
 
13
- print("πŸš€ Phase 2: Loading BART Weights...")
14
- model = BartForConditionalGeneration.from_pretrained(MODEL_ID, subfolder=SUBFOLDER)
15
 
16
  print("πŸš€ Phase 3: Building Pipeline...")
17
  summarizer = pipeline(
@@ -24,9 +28,17 @@ summarizer = pipeline(
24
  print("βœ… SUCCESS: Summarizer Ready!")
25
 
26
  def summarize_text(text):
27
- if not text: return "Input empty."
 
28
  results = summarizer(text, max_length=100, min_length=30, truncation=True)
29
  return results[0]['summary_text']
30
 
31
- demo = gr.Interface(fn=summarize_text, inputs="textbox", outputs="textbox")
32
- demo.launch()
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer
3
  import torch
4
 
5
  # 1. Configuration
6
  MODEL_ID = "VoltIC/Automated-Text-Summarizer"
7
  SUBFOLDER = "summarizer_model"
8
 
9
+ print("πŸš€ Phase 1: Loading Tokenizer...")
10
+ # use_fast=False is the magic fix for the NoneType/vocab_file error
11
+ tokenizer = AutoTokenizer.from_pretrained(
12
+ MODEL_ID,
13
+ subfolder=SUBFOLDER,
14
+ use_fast=False
15
+ )
16
 
17
+ print("πŸš€ Phase 2: Loading Model Weights...")
18
+ model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_ID, subfolder=SUBFOLDER)
19
 
20
  print("πŸš€ Phase 3: Building Pipeline...")
21
  summarizer = pipeline(
 
28
  print("βœ… SUCCESS: Summarizer Ready!")
29
 
30
  def summarize_text(text):
31
+ if not text: return "Input is empty."
32
+ # Truncation=True ensures we don't exceed the 1024 token limit
33
  results = summarizer(text, max_length=100, min_length=30, truncation=True)
34
  return results[0]['summary_text']
35
 
36
+ demo = gr.Interface(
37
+ fn=summarize_text,
38
+ inputs=gr.Textbox(lines=10, placeholder="Paste text here..."),
39
+ outputs="textbox",
40
+ title="AI Text Summarizer"
41
+ )
42
+
43
+ if __name__ == "__main__":
44
+ demo.launch()