priya9shu commited on
Commit
bd503b7
·
1 Parent(s): 2fac49e

Add application file

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from fastapi import FastAPI
4
+
5
+ # Initialize the summarization pipeline
6
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
7
+
8
+ # Define the summarization function
9
+ def summarize_text(input_text):
10
+ summary = summarizer(input_text, max_length=130, min_length=30, do_sample=False)
11
+ return summary[0]['summary_text']
12
+
13
+ # Create the Gradio app
14
+ app = gr.Interface(
15
+ fn=summarize_text,
16
+ inputs=gr.Textbox(lines=10, label="Input Text"),
17
+ outputs=gr.Textbox(label="Summarized Text"),
18
+ title="Text Summarization",
19
+ description="Enter a block of text to summarize it using the BART model fine-tuned on CNN/Daily Mail."
20
+ )
21
+
22
+ # Mount the Gradio app on FastAPI
23
+ fastapi_app = FastAPI()
24
+ fastapi_app.mount("/", app)
25
+
26
+ if __name__ == "__main__":
27
+ app.launch()