Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,45 +1,25 @@
|
|
| 1 |
from transformers import pipeline, set_seed
|
| 2 |
-
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
generator = pipeline('text-generation', model='gpt2')
|
| 8 |
-
|
| 9 |
set_seed(42)
|
| 10 |
|
| 11 |
def generate_text(prompt):
|
| 12 |
-
|
| 13 |
response = generator(
|
| 14 |
-
|
| 15 |
prompt,
|
| 16 |
-
|
| 17 |
max_length=100,
|
| 18 |
-
|
| 19 |
num_return_sequences=1,
|
| 20 |
-
|
| 21 |
truncation=True
|
| 22 |
-
|
| 23 |
)
|
| 24 |
-
|
| 25 |
return response[0]['generated_text']
|
| 26 |
|
| 27 |
-
# Interfaccia Gradio
|
| 28 |
-
|
| 29 |
interface = gr.Interface(
|
| 30 |
-
|
| 31 |
fn=generate_text,
|
| 32 |
-
|
| 33 |
-
inputs=gr.Textbox(lines=5, placeholder="Inserisci il tuo testo iniziale..."),
|
| 34 |
-
|
| 35 |
outputs="text",
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
description="Genera testo continuativo usando GPT-2 senza fine-tuning."
|
| 40 |
-
|
| 41 |
)
|
| 42 |
|
| 43 |
if __name__ == "__main__":
|
| 44 |
-
|
| 45 |
-
interface.launch()
|
|
|
|
| 1 |
from transformers import pipeline, set_seed
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
generator = pipeline('text-generation', model='Keyurjotaniya007/openai-gpt2-wikitext-textgen')
|
|
|
|
|
|
|
|
|
|
| 5 |
set_seed(42)
|
| 6 |
|
| 7 |
def generate_text(prompt):
|
|
|
|
| 8 |
response = generator(
|
|
|
|
| 9 |
prompt,
|
|
|
|
| 10 |
max_length=100,
|
|
|
|
| 11 |
num_return_sequences=1,
|
|
|
|
| 12 |
truncation=True
|
|
|
|
| 13 |
)
|
|
|
|
| 14 |
return response[0]['generated_text']
|
| 15 |
|
|
|
|
|
|
|
| 16 |
interface = gr.Interface(
|
|
|
|
| 17 |
fn=generate_text,
|
| 18 |
+
inputs=gr.Textbox(lines=5, placeholder="write something to generate..."),
|
|
|
|
|
|
|
| 19 |
outputs="text",
|
| 20 |
+
title="OpenAI GPT-2🦄",
|
| 21 |
+
description="Run text generation with the model `Keyurjotaniya007/openai-gpt2-wikitext-textgen`, a GPT-2 variant fine-tuned for coherent long-form text."
|
|
|
|
|
|
|
|
|
|
| 22 |
)
|
| 23 |
|
| 24 |
if __name__ == "__main__":
|
| 25 |
+
interface.launch()
|
|
|