PRIYANSHUDHAKED commited on
Commit
e5885c8
·
verified ·
1 Parent(s): 5ddcd1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py CHANGED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Initialize summarization pipeline
5
+ summarizer = pipeline("summarization", model="t5-small", revision="main")
6
+
7
+ # Function to summarize text
8
+ def summarize_text(text, model):
9
+ summary = model(text)[0]['summary_text']
10
+ return summary
11
+
12
+ # Function to read PDF and summarize
13
+ def summarize_pdf(pdf_file, model):
14
+ import fitz # PyMuPDF
15
+ with fitz.open(pdf_file.name) as doc:
16
+ text = ""
17
+ for page in doc:
18
+ text += page.get_text()
19
+ return summarize_text(text, model)
20
+
21
+ # Gradio Interface
22
+ def summarize(input_text, uploaded_file):
23
+ if input_text:
24
+ summary = summarize_text(input_text, summarizer)
25
+ else:
26
+ summary = summarize_pdf(uploaded_file, summarizer)
27
+ return summary
28
+
29
+ inputs = [
30
+ gr.Textbox(lines=10, label="Enter Text to Summarize"),
31
+ gr.File(label="Upload PDF file")
32
+ ]
33
+ output = gr.Textbox(label="Summary")
34
+
35
+ gr.Interface(
36
+ fn=summarize,
37
+ inputs=inputs,
38
+ outputs=output,
39
+ title="Text Summarization App",
40
+ description="Summarize text or PDF files using pre-trained models.",
41
+ theme="compact", # Example theme
42
+ layout="horizontal" # Example layout
43
+ ).launch()