Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,29 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
def generate(text):
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
["What is the fundamental difference between supervised and unsupervised learning"],
|
| 9 |
["What is overfitting in supervised learning"],
|
| 10 |
-
["What is a convolutional neural network
|
| 11 |
["Describe the concept of transfer learning and its significance in deep learning"]
|
| 12 |
-
|
| 13 |
]
|
|
|
|
|
|
|
| 14 |
run = gr.Interface(
|
| 15 |
fn=generate,
|
| 16 |
-
inputs=gr.
|
| 17 |
-
outputs=gr.
|
| 18 |
examples=examples
|
| 19 |
)
|
|
|
|
|
|
|
| 20 |
run.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the text generation pipeline
|
| 5 |
+
generator = pipeline('text-generation', model='gpt2')
|
| 6 |
+
|
| 7 |
+
# Define the function for text generation
|
| 8 |
def generate(text):
|
| 9 |
+
result = generator(text, max_length=100, num_return_sequences=1)
|
| 10 |
+
return result[0]['generated_text']
|
| 11 |
+
|
| 12 |
+
# Define examples
|
| 13 |
+
examples = [
|
| 14 |
["What is the fundamental difference between supervised and unsupervised learning"],
|
| 15 |
["What is overfitting in supervised learning"],
|
| 16 |
+
["What is a convolutional neural network"],
|
| 17 |
["Describe the concept of transfer learning and its significance in deep learning"]
|
|
|
|
| 18 |
]
|
| 19 |
+
|
| 20 |
+
# Create the Gradio interface
|
| 21 |
run = gr.Interface(
|
| 22 |
fn=generate,
|
| 23 |
+
inputs=gr.Textbox(lines=5, label="Input Text"),
|
| 24 |
+
outputs=gr.Textbox(label="Generated Text"),
|
| 25 |
examples=examples
|
| 26 |
)
|
| 27 |
+
|
| 28 |
+
# Launch the app
|
| 29 |
run.launch()
|