Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,30 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
|
|
3 |
|
4 |
-
# Load
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
outputs = model.generate(inputs, max_length=150, num_return_sequences=1, pad_token_id=tokenizer.eos_token_id)
|
15 |
-
text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
16 |
-
return text
|
17 |
|
18 |
# Gradio interface
|
19 |
-
def adventure_game(prompt, choice1, choice2, choice3):
|
20 |
-
story = generate_story(prompt, choice1, choice2, choice3)
|
21 |
-
return story
|
22 |
-
|
23 |
-
# Create Gradio interface
|
24 |
iface = gr.Interface(
|
25 |
-
fn=
|
26 |
inputs=[
|
27 |
-
gr.Textbox(label="
|
28 |
-
gr.
|
29 |
-
gr.Textbox(label="
|
30 |
-
gr.Textbox(label="
|
31 |
-
],
|
32 |
-
outputs="
|
33 |
-
title="
|
34 |
-
description="
|
35 |
)
|
36 |
|
37 |
iface.launch()
|
|
|
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()
|