Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,11 +6,15 @@ config = PeftConfig.from_pretrained("zeyadusf/FlanT5Summarization-samsum")
|
|
| 6 |
base_model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-large")
|
| 7 |
model = PeftModel.from_pretrained(base_model, "zeyadusf/FlanT5Summarization-samsum")
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained("zeyadusf/FlanT5Summarization-samsum")
|
|
|
|
|
|
|
| 9 |
def summarize(text):
|
| 10 |
inputs = tokenizer(text, return_tensors="pt", truncation=True)
|
| 11 |
-
|
|
|
|
| 12 |
return tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 13 |
|
| 14 |
# Define the Gradio interface
|
| 15 |
iface = gr.Interface(fn=summarize, inputs="text", outputs="text", title="Summarization with PEFT")
|
| 16 |
iface.launch()
|
|
|
|
|
|
| 6 |
base_model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-large")
|
| 7 |
model = PeftModel.from_pretrained(base_model, "zeyadusf/FlanT5Summarization-samsum")
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained("zeyadusf/FlanT5Summarization-samsum")
|
| 9 |
+
|
| 10 |
+
# Define the summarization function
|
| 11 |
def summarize(text):
|
| 12 |
inputs = tokenizer(text, return_tensors="pt", truncation=True)
|
| 13 |
+
# Access the base model's generate method
|
| 14 |
+
summary_ids = model.base_model.generate(inputs.input_ids, max_length=512, min_length=64, length_penalty=2.0, num_beams=4, early_stopping=True)
|
| 15 |
return tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 16 |
|
| 17 |
# Define the Gradio interface
|
| 18 |
iface = gr.Interface(fn=summarize, inputs="text", outputs="text", title="Summarization with PEFT")
|
| 19 |
iface.launch()
|
| 20 |
+
|