Shahadbal commited on
Commit
e119d5d
·
verified ·
1 Parent(s): ab1374f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -15
app.py CHANGED
@@ -1,30 +1,27 @@
1
  import gradio as gr
2
- from diffusers import StableDiffusionPipeline
3
- import torch
4
 
5
- # Load a lightweight stable diffusion model
6
- model_id = "CompVis/stable-diffusion-v1-4"
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 generate_character(name, gender, trait, superpower):
11
- description = f"A {gender} character named {name}, who is {trait}. Their superpower is {superpower}."
12
- # Generate an image based on the description
13
- image = pipe(description).images[0]
14
- return image
15
 
16
  # Gradio interface
17
  iface = gr.Interface(
18
- fn=generate_character,
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="image",
26
- title="Lightweight Character Generator",
27
- description="Enter the details of your character and generate an image!"
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()