Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load a lightweight model (GPT-2)
|
5 |
+
generator = pipeline("text-generation", model="gpt2")
|
6 |
+
|
7 |
+
def generate_completion(prompt):
|
8 |
+
outputs = generator(prompt, max_length=50, do_sample=True, temperature=0.9)
|
9 |
+
generated_text = outputs[0]['generated_text']
|
10 |
+
# Remove the original prompt from the returned completion
|
11 |
+
return generated_text[len(prompt):].strip()
|
12 |
+
|
13 |
+
iface = gr.Interface(
|
14 |
+
fn=generate_completion,
|
15 |
+
inputs=gr.Textbox(lines=1, placeholder="Enter your text here..."),
|
16 |
+
outputs="text"
|
17 |
+
)
|
18 |
+
|
19 |
+
iface.launch()
|