Update app.py
Browse files
app.py
CHANGED
@@ -24,6 +24,9 @@ inputs = [
|
|
24 |
gr.Textbox(label="Main Character", placeholder="e.g. a brave knight"),
|
25 |
gr.Textbox(label="Setting", placeholder="e.g. in an enchanted forest"),
|
26 |
gr.Textbox(label="Plot Twist", placeholder="e.g. discovers a hidden treasure")
|
|
|
|
|
|
|
27 |
]
|
28 |
|
29 |
outputs = gr.Textbox(label="Generated Story")
|
@@ -54,12 +57,12 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
54 |
return output_text
|
55 |
|
56 |
@spaces.GPU
|
57 |
-
def generate_story(character, setting, plot_twist):
|
58 |
"""Define the function to generate the story."""
|
59 |
prompt = f"Write a short story with the following details:\nMain character: {character}\nSetting: {setting}\nPlot twist: {plot_twist}\n\nStory:"
|
60 |
input_ids = tokenizer.encode(prompt, return_tensors="pt").to(model.device)
|
61 |
|
62 |
-
output_ids = model.generate(input_ids, max_length=
|
63 |
|
64 |
output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
65 |
|
|
|
24 |
gr.Textbox(label="Main Character", placeholder="e.g. a brave knight"),
|
25 |
gr.Textbox(label="Setting", placeholder="e.g. in an enchanted forest"),
|
26 |
gr.Textbox(label="Plot Twist", placeholder="e.g. discovers a hidden treasure")
|
27 |
+
gr.Slider(minimum=1, maximum=2048, value=64, step=1, label="Max new tokens"),
|
28 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
29 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
|
30 |
]
|
31 |
|
32 |
outputs = gr.Textbox(label="Generated Story")
|
|
|
57 |
return output_text
|
58 |
|
59 |
@spaces.GPU
|
60 |
+
def generate_story(character, setting, plot_twist, max_tokens, temperature, top_p):
|
61 |
"""Define the function to generate the story."""
|
62 |
prompt = f"Write a short story with the following details:\nMain character: {character}\nSetting: {setting}\nPlot twist: {plot_twist}\n\nStory:"
|
63 |
input_ids = tokenizer.encode(prompt, return_tensors="pt").to(model.device)
|
64 |
|
65 |
+
output_ids = model.generate(input_ids, max_length=max_tokens, num_return_sequences=1, temperature=temperature, top_p=top_p)
|
66 |
|
67 |
output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
68 |
|