Update app.py
Browse files
app.py
CHANGED
|
@@ -5,10 +5,17 @@ from transformers import pipeline
|
|
| 5 |
generator = pipeline('text-generation', model='distilgpt2')
|
| 6 |
|
| 7 |
def generate_character_description(name, gender, trait, superpower):
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Gradio interface
|
| 14 |
iface = gr.Interface(
|
|
|
|
| 5 |
generator = pipeline('text-generation', model='distilgpt2')
|
| 6 |
|
| 7 |
def generate_character_description(name, gender, trait, superpower):
|
| 8 |
+
# Construct the prompt with specific instructions for detailed descriptions
|
| 9 |
+
prompt = (f"Create a game senario of this character description. Name: {name}. "
|
| 10 |
+
f"Gender: {gender}. Personality Trait: {trait}. "
|
| 11 |
+
f"Superpower: {superpower}. Provide a short story or background for this character.")
|
| 12 |
+
|
| 13 |
+
# Generate the description
|
| 14 |
+
results = generator(prompt, max_length=150, num_return_sequences=1)
|
| 15 |
+
description = results[0]['generated_text']
|
| 16 |
+
|
| 17 |
+
# Clean up the output by removing the prompt part from the result
|
| 18 |
+
return description[len(prompt):].strip()
|
| 19 |
|
| 20 |
# Gradio interface
|
| 21 |
iface = gr.Interface(
|