TypeAI / app.py
Keyurjotaniya007's picture
Upload 2 files
bdbc895 verified
raw
history blame
708 Bytes
from transformers import pipeline, set_seed
import gradio as gr
# Carica il modello GPT-2
generator = pipeline('text-generation', model='gpt2')
set_seed(42)
def generate_text(prompt):
response = generator(
prompt,
max_length=100,
num_return_sequences=1,
truncation=True
)
return response[0]['generated_text']
# Interfaccia Gradio
interface = gr.Interface(
fn=generate_text,
inputs=gr.Textbox(lines=5, placeholder="Inserisci il tuo testo iniziale..."),
outputs="text",
title="GPT-2 Text Generator",
description="Genera testo continuativo usando GPT-2 senza fine-tuning."
)
if __name__ == "__main__":
interface.launch()