Spaces:
Runtime error
Runtime error
MaawaKhalid
commited on
Commit
•
dee7fc8
1
Parent(s):
e4b4fe5
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
+
|
4 |
+
# Load the tokenizer and model
|
5 |
+
model_checkpoint = "google/mt5-small"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
|
7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)
|
8 |
+
|
9 |
+
def summarize(text):
|
10 |
+
inputs = tokenizer.encode("summarize: " + text, return_tensors="pt", max_length=1024, truncation=True)
|
11 |
+
outputs = model.generate(inputs, max_length=150, min_length=30, length_penalty=2.0, num_beams=4, early_stopping=True)
|
12 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
13 |
+
|
14 |
+
iface = gr.Interface(fn=summarize, inputs="text", outputs="text", title="Text Summarizer", description="Summarize any text using the mT5 model.")
|
15 |
+
|
16 |
+
iface.launch()
|