Spaces:
Build error
Build error
| import gradio as gr | |
| from transformers import pipeline | |
| # Load the text generation pipeline | |
| pipe = pipeline("text-generation", model="openai-community/gpt2") | |
| # Define the function for text generation | |
| def generate(text): | |
| result = pipe(text, max_length=69, num_return_sequences=5) | |
| return result[0]['generated_text'] | |
| # Define examples | |
| examples = [ | |
| ["What is the fundamental difference between supervised and unsupervised learning"], | |
| ["What is overfitting in supervised learning"], | |
| ["What is a convolutional neural network"], | |
| ["Describe the concept of transfer learning and its significance in deep learning"] | |
| ] | |
| # Create the Gradio interface | |
| run = gr.Interface( | |
| fn=generate, | |
| inputs=gr.Textbox(lines=5, label="Input Text"), | |
| outputs=gr.Textbox(label="Generated Text"), | |
| examples=examples | |
| ) | |
| # Launch the app | |
| run.launch() |