Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- README.md +2 -8
- requirements.txt +2 -0
- runningboi.py +33 -0
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
-
title: GPT-
|
3 |
-
|
4 |
-
colorFrom: blue
|
5 |
-
colorTo: pink
|
6 |
sdk: gradio
|
7 |
sdk_version: 5.4.0
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: GPT-2_Prompt
|
3 |
+
app_file: runningboi.py
|
|
|
|
|
4 |
sdk: gradio
|
5 |
sdk_version: 5.4.0
|
|
|
|
|
6 |
---
|
|
|
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
gradio
|
runningboi.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
3 |
+
|
4 |
+
# Load the GPT-2 small model and tokenizer
|
5 |
+
model_name = "gpt2"
|
6 |
+
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
7 |
+
model = GPT2LMHeadModel.from_pretrained(model_name)
|
8 |
+
|
9 |
+
def generate_text(prompt):
|
10 |
+
# Encode the input prompt
|
11 |
+
inputs = tokenizer.encode(prompt, return_tensors="pt")
|
12 |
+
|
13 |
+
# Generate text
|
14 |
+
outputs = model.generate(inputs, max_length=100, num_return_sequences=1)
|
15 |
+
|
16 |
+
# Decode the generated text
|
17 |
+
text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
18 |
+
return text
|
19 |
+
|
20 |
+
# Set up the Gradio interface with dynamic generation
|
21 |
+
iface = gr.Interface(
|
22 |
+
fn=generate_text,
|
23 |
+
inputs=gr.Textbox(label="Enter Prompt", placeholder="Type your prompt here..."),
|
24 |
+
outputs=gr.Textbox(label="Generated Text"),
|
25 |
+
title="GPT-2 Text Generator",
|
26 |
+
description="Enter a prompt to generate text using GPT-2 small. The text will update dynamically as you type."
|
27 |
+
|
28 |
+
)
|
29 |
+
|
30 |
+
# Launch the app
|
31 |
+
iface.launch(
|
32 |
+
share=True
|
33 |
+
)
|