Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,39 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from gradio import mix
|
|
|
|
|
|
|
| 3 |
|
| 4 |
title = "Miniature"
|
| 5 |
description = "Gradio Demo for a miniature with GPT. To use it, simply add your text, or click one of the examples to load them. Read more at the links below."
|
| 6 |
|
| 7 |
|
| 8 |
-
examples = [
|
| 9 |
-
['A kid is playing with']
|
| 10 |
-
]
|
| 11 |
|
| 12 |
-
|
| 13 |
|
|
|
|
|
|
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
gr.Interface(
|
| 23 |
-
|
| 24 |
-
[gr.inputs.Textbox(label="Input")],
|
| 25 |
-
gr.outputs.Textbox(label="Output"),
|
| 26 |
-
examples=examples,
|
| 27 |
-
# article=article,
|
| 28 |
-
title=title,
|
| 29 |
-
description=description).launch(enable_queue=True, cache_examples=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from gradio import mix
|
| 3 |
+
import torch
|
| 4 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 5 |
|
| 6 |
title = "Miniature"
|
| 7 |
description = "Gradio Demo for a miniature with GPT. To use it, simply add your text, or click one of the examples to load them. Read more at the links below."
|
| 8 |
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
tokenizer = AutoTokenizer.from_pretrained("aditi2222/automatic_title_generation")
|
| 12 |
|
| 13 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("aditi2222/automatic_title_generation")
|
| 14 |
+
|
| 15 |
|
| 16 |
+
def tokenize_data(text):
|
| 17 |
+
# Tokenize the review body
|
| 18 |
+
input_ = str(text) + ' </s>'
|
| 19 |
+
max_len = 120
|
| 20 |
+
# tokenize inputs
|
| 21 |
+
tokenized_inputs = tokenizer(input_, padding='max_length', truncation=True, max_length=max_len, return_attention_mask=True, return_tensors='pt')
|
| 22 |
|
| 23 |
+
inputs={"input_ids": tokenized_inputs['input_ids'],
|
| 24 |
+
"attention_mask": tokenized_inputs['attention_mask']}
|
| 25 |
+
return inputs
|
| 26 |
|
| 27 |
+
def generate_answers(text):
|
| 28 |
+
inputs = tokenize_data(text)
|
| 29 |
+
results= model.generate(input_ids= inputs['input_ids'], attention_mask=inputs['attention_mask'], do_sample=True,
|
| 30 |
+
max_length=120,
|
| 31 |
+
top_k=120,
|
| 32 |
+
top_p=0.98,
|
| 33 |
+
early_stopping=True,
|
| 34 |
+
num_return_sequences=1)
|
| 35 |
+
answer = tokenizer.decode(results[0], skip_special_tokens=True)
|
| 36 |
+
return answer
|
| 37 |
|
| 38 |
+
iface = gr.Interface(fn=generate_answers, inputs=['text'], outputs=["text"])
|
| 39 |
+
iface.launch(inline=False, share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|