Spaces:
Sleeping
Sleeping
Commit
·
c237b84
1
Parent(s):
448f310
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Import the libraries
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import transformers
|
| 4 |
+
from transformers import GPT2Tokenizer, GPT2LMHeadModel
|
| 5 |
+
|
| 6 |
+
# Load the tokenizer and model
|
| 7 |
+
tokenizer = GPT2Tokenizer.from_pretrained('DarwinAnim8or/gpt-grug-1.5b')
|
| 8 |
+
model = GPT2LMHeadModel.from_pretrained('DarwinAnim8or/gpt-grug-1.5b')
|
| 9 |
+
|
| 10 |
+
# Define the function that generates text from a prompt
|
| 11 |
+
def generate_text(prompt):
|
| 12 |
+
input_ids = tokenizer.encode(prompt, return_tensors='pt')
|
| 13 |
+
output = model.generate(input_ids, max_length=80, do_sample=True)
|
| 14 |
+
text = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 15 |
+
return text
|
| 16 |
+
|
| 17 |
+
# Create a gradio interface with a text input and a text output
|
| 18 |
+
interface = gr.Interface(fn=generate_text, inputs='text', outputs='text')
|
| 19 |
+
interface.launch()
|