Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import transformers
|
| 2 |
+
from huggingface_hub import notebook_login
|
| 3 |
+
from datasets import load_dataset
|
| 4 |
+
from transformers import AutoModelForSequenceClassification
|
| 5 |
+
from transformers import AutoTokenizer
|
| 6 |
+
model_checkpoint = "distilgpt2"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint, use_fast=True)
|
| 8 |
+
from transformers import pipeline
|
| 9 |
+
import gradio as gr
|
| 10 |
+
from transformers import pipeline
|
| 11 |
+
|
| 12 |
+
generator = pipeline('text-generation', model='DioLiu/GPT2_Suggestion',tokenizer=tokenizer)
|
| 13 |
+
def get_suggestion(input_text):
|
| 14 |
+
answer=generator(input_text, max_length=200, num_return_sequences=1)[0]['generated_text']
|
| 15 |
+
if answer.find('\n\nGiven')!=-1:
|
| 16 |
+
output=answer[0:answer.find('\n\nGiven')]
|
| 17 |
+
else:
|
| 18 |
+
output=answer[0:answer.rfind('.')+1]
|
| 19 |
+
return output
|
| 20 |
+
iface = gr.Interface(fn= get_suggestion, inputs="text", outputs = ["text"], title="Suggestions")
|
| 21 |
+
iface.launch()
|