Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,27 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
import torch
|
4 |
|
5 |
-
# Load a
|
6 |
-
|
7 |
-
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
8 |
-
pipe = pipe.to("cuda") # Use GPU for faster generation, or .to("cpu") if no GPU is available
|
9 |
|
10 |
-
def
|
11 |
-
|
12 |
-
# Generate
|
13 |
-
|
14 |
-
return
|
15 |
|
16 |
# Gradio interface
|
17 |
iface = gr.Interface(
|
18 |
-
fn=
|
19 |
inputs=[
|
20 |
gr.Textbox(label="Name", placeholder="Enter the character's name"),
|
21 |
gr.Radio(label="Gender", choices=["male", "female", "non-binary"]),
|
22 |
gr.Textbox(label="Personality Trait", placeholder="e.g., brave, clever, kind"),
|
23 |
gr.Textbox(label="Superpower", placeholder="e.g., flying, invisibility, super strength")
|
24 |
],
|
25 |
-
outputs="
|
26 |
-
title="
|
27 |
-
description="Enter
|
28 |
)
|
29 |
|
30 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
|
|
3 |
|
4 |
+
# Load a text generation model (GPT-2 for simplicity)
|
5 |
+
generator = pipeline('text-generation', model='gpt2')
|
|
|
|
|
6 |
|
7 |
+
def generate_character_description(name, gender, trait, superpower):
|
8 |
+
prompt = f"Generate a detailed description of a character named {name}. They are {gender}, {trait}, and their superpower is {superpower}. Provide a short story or background for this character."
|
9 |
+
# Generate the description based on the prompt
|
10 |
+
description = generator(prompt, max_length=200)[0]['generated_text']
|
11 |
+
return description
|
12 |
|
13 |
# Gradio interface
|
14 |
iface = gr.Interface(
|
15 |
+
fn=generate_character_description,
|
16 |
inputs=[
|
17 |
gr.Textbox(label="Name", placeholder="Enter the character's name"),
|
18 |
gr.Radio(label="Gender", choices=["male", "female", "non-binary"]),
|
19 |
gr.Textbox(label="Personality Trait", placeholder="e.g., brave, clever, kind"),
|
20 |
gr.Textbox(label="Superpower", placeholder="e.g., flying, invisibility, super strength")
|
21 |
],
|
22 |
+
outputs="text",
|
23 |
+
title="Character Description Generator",
|
24 |
+
description="Enter details about your character to generate a description or background story!"
|
25 |
)
|
26 |
|
27 |
iface.launch()
|