HamidBekam
commited on
Commit
·
07418f0
1
Parent(s):
e28bf13
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer
|
3 |
+
|
4 |
+
# Load model and tokenizer
|
5 |
+
model_name = "t5-base"
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
|
9 |
+
# Define pipeline for text summarization
|
10 |
+
summarizer = pipeline('text2text-generation', model=model, tokenizer=tokenizer)
|
11 |
+
|
12 |
+
# Define Gradio interface
|
13 |
+
def summarize_text(text):
|
14 |
+
result = summarizer(text, max_length=100, min_length=30, do_sample=False)[0]
|
15 |
+
summary = result['generated_text'].strip()
|
16 |
+
return summary
|
17 |
+
|
18 |
+
iface = gr.Interface(fn=summarize_text, inputs="text", outputs="text",
|
19 |
+
title="Text Summarization with Hugging Face and Gradio",
|
20 |
+
description="Enter text to summarize.")
|
21 |
+
|
22 |
+
# Launch Gradio interface
|
23 |
+
iface.launch()
|