Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,20 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
-
import torch
|
4 |
-
from PIL import Image
|
5 |
-
import requests
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
model = AutoModelForCausalLM.from_pretrained(model_name)
|
11 |
-
feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)
|
12 |
|
13 |
-
def
|
14 |
-
inputs =
|
15 |
-
|
16 |
-
|
17 |
-
return caption
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
inputs=gr.inputs.Image(type="pil"),
|
22 |
outputs="text",
|
23 |
-
title="
|
24 |
-
description="
|
25 |
|
26 |
if __name__ == "__main__":
|
27 |
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import BartTokenizer, BartForConditionalGeneration
|
|
|
|
|
|
|
3 |
|
4 |
+
model_name = "facebook/bart-large-cnn" # Example BART model
|
5 |
+
tokenizer = BartTokenizer.from_pretrained(model_name)
|
6 |
+
model = BartForConditionalGeneration.from_pretrained(model_name)
|
|
|
|
|
7 |
|
8 |
+
def generate_text(prompt):
|
9 |
+
inputs = tokenizer.encode("summarize: " + prompt, return_tensors="pt", max_length=1024, truncation=True)
|
10 |
+
summary_ids = model.generate(inputs, max_length=150, min_length=40, length_penalty=2.0, num_beams=4, early_stopping=True)
|
11 |
+
return tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
|
|
12 |
|
13 |
+
interface = gr.Interface(fn=generate_text,
|
14 |
+
inputs=gr.inputs.Textbox(lines=5, placeholder="Enter Text Here..."),
|
|
|
15 |
outputs="text",
|
16 |
+
title="Text Generation with BART",
|
17 |
+
description="Enter text to generate a summary.")
|
18 |
|
19 |
if __name__ == "__main__":
|
20 |
interface.launch()
|