VoltIC commited on
Commit
4303a27
Β·
verified Β·
1 Parent(s): 6c4b767

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -25
app.py CHANGED
@@ -1,45 +1,32 @@
1
  import gradio as gr
2
- from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer
3
  import torch
4
 
5
- # 1. Setup
6
  MODEL_ID = "VoltIC/Automated-Text-Summarizer"
7
  SUBFOLDER = "summarizer_model"
8
 
9
- # 2. Initialization (No 'try' block here so we can see the real error in logs)
10
- print("πŸš€ Phase 1: Loading Tokenizer...")
11
- tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, subfolder=SUBFOLDER)
12
 
13
- print("πŸš€ Phase 2: Loading Model Weights (1.6GB)...")
14
- model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_ID, subfolder=SUBFOLDER)
15
 
16
  print("πŸš€ Phase 3: Building Pipeline...")
17
- # This defines the 'summarizer' variable globally
18
  summarizer = pipeline(
19
  "summarization",
20
  model=model,
21
  tokenizer=tokenizer,
22
  framework="pt",
23
- device=-1 # Forces CPU
24
  )
25
- print("βœ… SUCCESS: Summarizer is now defined!")
26
 
27
- # 3. Logic
28
  def summarize_text(text):
29
- if not text:
30
- return "Please enter text."
31
-
32
- # We use the global 'summarizer' defined above
33
  results = summarizer(text, max_length=100, min_length=30, truncation=True)
34
  return results[0]['summary_text']
35
 
36
- # 4. Interface
37
- demo = gr.Interface(
38
- fn=summarize_text,
39
- inputs=gr.Textbox(lines=10, label="Input Text"),
40
- outputs=gr.Textbox(label="Summary"),
41
- title="AI Text Summarizer"
42
- )
43
-
44
- if __name__ == "__main__":
45
- demo.launch()
 
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(
18
  "summarization",
19
  model=model,
20
  tokenizer=tokenizer,
21
  framework="pt",
22
+ device=-1
23
  )
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()