Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,22 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
# Load
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load a free pipeline model from Hugging Face
|
| 5 |
+
generator = pipeline("text-generation", model="gpt2")
|
| 6 |
+
|
| 7 |
+
def generate_text(user_input):
|
| 8 |
+
# Process the user input through the AI model
|
| 9 |
+
result = generator(user_input, max_length=50, num_return_sequences=1)
|
| 10 |
+
return result[0]['generated_text']
|
| 11 |
+
|
| 12 |
+
# Build the Gradio interface
|
| 13 |
+
demo = gr.Interface(
|
| 14 |
+
fn=generate_text,
|
| 15 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter a prompt here..."),
|
| 16 |
+
outputs="text",
|
| 17 |
+
title="My First AI Assistant"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
# Launch the app
|
| 21 |
+
if __name__ == "__main__":
|
| 22 |
+
demo.launch()
|