VoltIC commited on
Commit
45c4e43
Β·
verified Β·
1 Parent(s): 68173c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -38
app.py CHANGED
@@ -1,44 +1,41 @@
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(
22
- "summarization",
23
- model=model,
24
- tokenizer=tokenizer,
25
- framework="pt",
26
- device=-1
27
- )
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()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
+ import os
4
 
5
+ # 1. Load the model
6
+ # NOTE: Ensure your model is PUBLIC on Hugging Face
7
+ try:
8
+ pipe = pipeline("summarization", model="VoltIC/Automated-Text-Summarizer")
9
+ status = "Model loaded successfully!"
10
+ except Exception as e:
11
+ pipe = None
12
+ status = f"Error: {str(e)}"
13
 
14
+ def summarize(text):
15
+ if pipe is None:
16
+ return "Model not available. Check if repo is Public."
17
+ if not text.strip():
18
+ return "Please enter text."
19
+
20
+ result = pipe(text, max_length=130, min_length=30, do_sample=False)
21
+ return result[0]['summary_text']
22
 
23
+ # 2. Build UI using Blocks (Avoids the Interface IndexError)
24
+ with gr.Blocks() as app:
25
+ gr.Markdown("# Aditya's Automated Text Summarizer")
26
+ gr.Markdown(f"**Status:** {status}")
27
+
28
+ with gr.Row():
29
+ input_text = gr.Textbox(lines=10, label="Input Article", placeholder="Paste text here...")
30
+
31
+ with gr.Row():
32
+ submit_btn = gr.Button("Summarize")
33
+
34
+ with gr.Row():
35
+ output_text = gr.Textbox(label="Summary")
36
+
37
+ submit_btn.click(fn=summarize, inputs=input_text, outputs=output_text)
 
 
 
 
 
 
 
 
 
 
38
 
39
+ # 3. Launch
40
  if __name__ == "__main__":
41
+ app.launch()