Spaces:
Running
on
Zero
Running
on
Zero
alfredplpl
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -14,45 +14,9 @@ dtype = torch.float16
|
|
14 |
repo = "stabilityai/stable-diffusion-3-medium"
|
15 |
t2i = StableDiffusion3Pipeline.from_pretrained(repo, torch_dtype=torch.float16, revision="refs/pr/26",token=os.environ["TOKEN"]).to(device)
|
16 |
|
17 |
-
model_id = "microsoft/Phi-3-medium-128k-instruct"
|
18 |
-
upsampler = AutoModelForCausalLM.from_pretrained(
|
19 |
-
model_id,
|
20 |
-
device_map=device,
|
21 |
-
torch_dtype=torch.bfloat16,
|
22 |
-
trust_remote_code=True,
|
23 |
-
)
|
24 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
25 |
-
|
26 |
MAX_SEED = np.iinfo(np.int32).max
|
27 |
MAX_IMAGE_SIZE = 1344
|
28 |
|
29 |
-
if(0):
|
30 |
-
print("start inference...")
|
31 |
-
if randomize_seed:
|
32 |
-
seed = random.randint(0, MAX_SEED)
|
33 |
-
|
34 |
-
generator = torch.Generator().manual_seed(seed)
|
35 |
-
|
36 |
-
messages = [
|
37 |
-
{"role": "user", "content": "クールなアニメ風の少女"},
|
38 |
-
{"role": "assistant", "content": "An anime style illustration of a cool-looking teenage girl with an edgy, confident expression. She has piercing eyes, a slight smirk, and colorful hair that flows in the wind. She wears a trendy punk-inspired outfit with a leather jacket, ripped jeans, and combat boots. The background has an urban nighttime feel with city lights and graffiti to match her rebellious vibe. The colors are vibrant with high contrast to give an impactful look. The overall style captures her undeniable coolness and fearless attitude."},
|
39 |
-
{"role": "user", "content": "美味しそうな肉"},
|
40 |
-
{"role": "assistant", "content": "A gourmet scene in a high-end restaurant kitchen where a chef is presenting a plate of cooked beef testicles, garnished elegantly with herbs and spices. The chef, a middle-aged Caucasian man wearing a white chef's hat and coat, is inspecting the dish with a satisfied expression. The kitchen background is bustling with other chefs and kitchen staff, and the atmosphere is warm and inviting with hanging pots and pans, and a glowing, busy stove in the background. The focus is on the chef's proud presentation of this unusual but delicately prepared dish."},
|
41 |
-
{"role": "user", "content": prompt},
|
42 |
-
]
|
43 |
-
tokenized_input = tokenizer.apply_chat_templete(messages, add_generation_prompt=True, return_tensors="pt")
|
44 |
-
with torch.inference_mode():
|
45 |
-
output = upsampler.generate(
|
46 |
-
tokenized_input.to(upsampler.device),
|
47 |
-
max_new_tokens=512,
|
48 |
-
do_sample=True,
|
49 |
-
top_p=0.95,
|
50 |
-
temperature=0.7,
|
51 |
-
repetition_penalty=1.05,
|
52 |
-
)[0]
|
53 |
-
print(tokenizer.decode(output))
|
54 |
-
upsampled_prompt=tokenizer.decode(output)
|
55 |
-
|
56 |
@spaces.GPU
|
57 |
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, progress=gr.Progress(track_tqdm=True)):
|
58 |
upsampled_prompt="An anime style illustration of a cool-looking teenage girl with an edgy, confident expression. She has piercing eyes, a slight smirk, and colorful hair that flows in the wind. She wears a trendy punk-inspired outfit with a leather jacket, ripped jeans, and combat boots. The background has an urban nighttime feel with city lights and graffiti to match her rebellious vibe. The colors are vibrant with high contrast to give an impactful look. The overall style captures her undeniable coolness and fearless attitude."
|
|
|
14 |
repo = "stabilityai/stable-diffusion-3-medium"
|
15 |
t2i = StableDiffusion3Pipeline.from_pretrained(repo, torch_dtype=torch.float16, revision="refs/pr/26",token=os.environ["TOKEN"]).to(device)
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
MAX_SEED = np.iinfo(np.int32).max
|
18 |
MAX_IMAGE_SIZE = 1344
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
@spaces.GPU
|
21 |
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, progress=gr.Progress(track_tqdm=True)):
|
22 |
upsampled_prompt="An anime style illustration of a cool-looking teenage girl with an edgy, confident expression. She has piercing eyes, a slight smirk, and colorful hair that flows in the wind. She wears a trendy punk-inspired outfit with a leather jacket, ripped jeans, and combat boots. The background has an urban nighttime feel with city lights and graffiti to match her rebellious vibe. The colors are vibrant with high contrast to give an impactful look. The overall style captures her undeniable coolness and fearless attitude."
|