Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # Load the distilgpt2 model | |
| generator = pipeline("text-generation", model="distilgpt2") | |
| # Define the function to generate dynamic responses | |
| def generate_text(prompt): | |
| result = generator( | |
| prompt, | |
| max_length=50, # Control the length of the output | |
| temperature=0.7, # Balance between predictability and creativity | |
| top_p=0.9, # Focus on likely words to maintain relevance | |
| num_return_sequences=1 # Return only one response | |
| ) | |
| return result[0]['generated_text'] | |
| # Create the Gradio interface | |
| interface = gr.Interface( | |
| fn=generate_text, | |
| inputs="text", | |
| outputs="text", | |
| title="Conversational AI with distilgpt2", | |
| description="Enter instructions or prompts, and the model will generate text accordingly.", | |
| ) | |
| # Launch the interface | |
| interface.launch() | |