Spaces:
Runtime error
Runtime error
Commit
·
a997f81
1
Parent(s):
4916b2f
Upload model.tts
Browse files
model.tts
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
!pip install transformers
|
2 |
+
|
3 |
+
import torch
|
4 |
+
from transformers import GPT2Tokenizer, GPT2LMHeadModel
|
5 |
+
|
6 |
+
# Load the GPT-3 model and tokenizer
|
7 |
+
tokenizer = GPT2Tokenizer.from_pretrained("stuheart86/EleutherAI-gpt-neo-1.3B")
|
8 |
+
model = GPT2LMHeadModel.from_pretrained("stuheart86/EleutherAI-gpt-neo-1.3B")
|
9 |
+
|
10 |
+
# Generate a story based on inputs
|
11 |
+
def generate_story(inputs):
|
12 |
+
genre = inputs["genre"]
|
13 |
+
story_teller = inputs["story_teller"]
|
14 |
+
story_telling_style = inputs["story_telling_style"]
|
15 |
+
creativity = inputs["creativity"]
|
16 |
+
|
17 |
+
# Use the inputs to prompt the GPT-3 model
|
18 |
+
prompt = f"Write a {genre} story told by a {story_teller} in a {story_telling_style} style with {creativity} creativity."
|
19 |
+
encoded_prompt = tokenizer.encode(prompt, return_tensors="pt")
|
20 |
+
generated_story = model.generate(encoded_prompt, max_length=200, num_return_sequences=1)
|
21 |
+
decoded_story = tokenizer.decode(generated_story.tolist()[0])
|
22 |
+
|
23 |
+
return decoded_story
|