Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
+
|
| 4 |
+
# Load the model and tokenizer from Hugging Face Model Hub
|
| 5 |
+
tokenizer = AutoTokenizer.from_pretrained("zeyadusf/FlanT5Summarization-samsum")
|
| 6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("zeyadusf/FlanT5Summarization-samsum")
|
| 7 |
+
|
| 8 |
+
def summarize(text):
|
| 9 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True)
|
| 10 |
+
summary_ids = model.generate(inputs.input_ids, max_length=512, min_length=64, length_penalty=2.0, num_beams=4, early_stopping=True)
|
| 11 |
+
return tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 12 |
+
|
| 13 |
+
# Define the Gradio interface
|
| 14 |
+
iface = gr.Interface(fn=summarize, inputs="text", outputs="text", title="Summarization with PEFT")
|
| 15 |
+
iface.launch()
|