Spaces:
Sleeping
Sleeping
BusinessDev
commited on
Commit
•
7e21dc1
1
Parent(s):
19284c7
trans
Browse files
app.py
CHANGED
@@ -1,8 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
|
5 |
-
|
|
|
6 |
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load the text generation model
|
5 |
+
model_id = "gpt2" # You can replace this with any model of your choice
|
6 |
+
generator = pipeline("text-generation", model=model_id)
|
7 |
|
8 |
+
# Define the function to process the input and generate text
|
9 |
+
def generate_text(prompt):
|
10 |
+
response = generator(prompt, max_length=50, num_return_sequences=1)
|
11 |
+
generated_text = response[0]['generated_text']
|
12 |
+
return generated_text
|
13 |
+
|
14 |
+
# Create the Gradio interface
|
15 |
+
iface = gr.Interface(
|
16 |
+
fn=generate_text,
|
17 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
18 |
+
outputs="text",
|
19 |
+
title="Text Generation",
|
20 |
+
description="Enter a prompt and the model will generate text based on it."
|
21 |
+
)
|
22 |
+
|
23 |
+
# Launch the interface
|
24 |
+
if __name__ == "__main__":
|
25 |
+
iface.launch()
|