VoltIC commited on
Commit
4ffdf58
Β·
verified Β·
1 Parent(s): 3527e48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -17
app.py CHANGED
@@ -1,18 +1,21 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
- import torch
4
 
 
5
  MODEL_ID = "VoltIC/Automated-Text-Summarizer"
 
 
 
6
 
7
- # Load the model with low_cpu_mem_usage to save RAM
8
- print("πŸš€ Initializing model...")
9
  try:
 
 
 
10
  summarizer = pipeline(
11
  "summarization",
12
- model=MODEL_ID,
13
- subfolder="summarizer_model",
14
- framework="pt",
15
- device=-1 # Explicitly force CPU
16
  )
17
  print("βœ… System Ready")
18
  except Exception as e:
@@ -23,25 +26,23 @@ def summarize_text(text):
23
  return "Error: Text is too short."
24
 
25
  try:
26
- # TRUNCATION is the key.
27
- # It prevents the model from trying to process 10,000 words at once.
28
  result = summarizer(
29
  text,
30
  max_length=100,
31
  min_length=30,
32
  do_sample=False,
33
- truncation=True # πŸ‘ˆ This prevents memory crashes
34
  )
35
  return result[0]['summary_text']
36
  except Exception as e:
37
  return f"Runtime Error: {str(e)}"
38
 
39
- # Define the UI
40
- with gr.Blocks() as demo:
41
- gr.Markdown("# AI Summarizer")
42
- input_box = gr.Textbox(label="Input", lines=5)
43
- output_box = gr.Textbox(label="Result", lines=5)
44
- btn = gr.Button("Summarize")
45
 
46
  btn.click(fn=summarize_text, inputs=input_box, outputs=output_box)
47
 
 
1
  import gradio as gr
2
+ from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer
 
3
 
4
+ # 1. Configuration
5
  MODEL_ID = "VoltIC/Automated-Text-Summarizer"
6
+ SUBFOLDER = "summarizer_model"
7
+
8
+ print("πŸš€ Loading model and tokenizer...")
9
 
 
 
10
  try:
11
+ model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_ID, subfolder=SUBFOLDER)
12
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, subfolder=SUBFOLDER)
13
+
14
  summarizer = pipeline(
15
  "summarization",
16
+ model=model,
17
+ tokenizer=tokenizer,
18
+ framework="pt"
 
19
  )
20
  print("βœ… System Ready")
21
  except Exception as e:
 
26
  return "Error: Text is too short."
27
 
28
  try:
 
 
29
  result = summarizer(
30
  text,
31
  max_length=100,
32
  min_length=30,
33
  do_sample=False,
34
+ truncation=True
35
  )
36
  return result[0]['summary_text']
37
  except Exception as e:
38
  return f"Runtime Error: {str(e)}"
39
 
40
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
41
+ gr.Markdown("# πŸ“ AI Text Summarizer")
42
+ with gr.Column():
43
+ input_box = gr.Textbox(label="Input Text", lines=8)
44
+ output_box = gr.Textbox(label="Summary Result", lines=4)
45
+ btn = gr.Button("Summarize", variant="primary")
46
 
47
  btn.click(fn=summarize_text, inputs=input_box, outputs=output_box)
48