Sammi / app.py
priya9shu's picture
back to square 1
bb91118
raw
history blame contribute delete
877 Bytes
import gradio as gr
from transformers import pipeline
from fastapi import FastAPI
# Initialize the summarization pipeline
summarizer = pipeline("summarization", model="RMWeerasinghe/text_summarization-finetuned_cnn_dailymail")
# Define the summarization function
def summarize_text(input_text):
summary = summarizer(input_text, max_length=600, min_length=30, do_sample=False)
return summary[0]['summary_text']
# Create the Gradio app
app = gr.Interface(
fn=summarize_text,
inputs=gr.Textbox(lines=10, label="Input Text"),
outputs=gr.Textbox(label="Summarized Text"),
title="Text Summarization",
description="Enter a block of text to summarize it using fine-tuned CNN/Daily Mail model.",
api_name="predict"
)
# Mount the Gradio app on FastAPI
fastapi_app = FastAPI()
fastapi_app.mount("/", app)
if __name__ == "__main__":
app.launch()