Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load a pre-trained language model
|
5 |
+
generator = pipeline("text-generation", model="gpt2")
|
6 |
+
|
7 |
+
def generate_text(prompt):
|
8 |
+
return generator(prompt, max_length=50, num_return_sequences=1)[0]["generated_text"]
|
9 |
+
|
10 |
+
# Gradio interface
|
11 |
+
iface = gr.Interface(
|
12 |
+
fn=generate_text,
|
13 |
+
inputs="text",
|
14 |
+
outputs="text",
|
15 |
+
title="LLM Text Generator",
|
16 |
+
description="Generate text using a pre-trained GPT-2 model."
|
17 |
+
)
|
18 |
+
|
19 |
+
if __name__ == "__main__":
|
20 |
+
iface.launch()
|