|
import gradio as gr |
|
from transformers import pipeline |
|
from fastapi import FastAPI |
|
|
|
|
|
summarizer = pipeline("summarization", model="RMWeerasinghe/text_summarization-finetuned_cnn_dailymail") |
|
|
|
|
|
|
|
def summarize_text(input_text): |
|
summary = summarizer(input_text, max_length=600, min_length=30, do_sample=False) |
|
return summary[0]['summary_text'] |
|
|
|
|
|
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" |
|
) |
|
|
|
|
|
fastapi_app = FastAPI() |
|
fastapi_app.mount("/", app) |
|
|
|
if __name__ == "__main__": |
|
app.launch() |
|
|