Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import random
|
| 3 |
+
from smolagents import CodeAgent, InferenceClientModel
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 7 |
+
model_id = "mistralai/Mistral-7B-Instruct-v0.1"
|
| 8 |
+
|
| 9 |
+
client_model = InferenceClientModel(
|
| 10 |
+
model_id=model_id,
|
| 11 |
+
token=HF_TOKEN,
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
agent = CodeAgent(
|
| 15 |
+
llm=client_model,
|
| 16 |
+
system_message="You are a prompt generator specialized in hyper-realistic cosplay portrait prompts."
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
CHARACTER_FEMALES = [
|
| 20 |
+
{"name": "Rias Gremory", "series": "High School DxD", "description": "crimson hair styled in long waves, school uniform with a short skirt", "eye_color": "blue", "hair_color": "crimson"},
|
| 21 |
+
{"name": "Tifa Lockhart", "series": "Final Fantasy VII", "description": "black hair in ponytail, sporty tank top and mini skirt", "eye_color": "brown", "hair_color": "black"},
|
| 22 |
+
{"name": "Mikasa Ackerman", "series": "Attack on Titan", "description": "short black hair, scout uniform, fitted jacket and pants", "eye_color": "gray", "hair_color": "black"},
|
| 23 |
+
{"name": "Sailor Moon", "series": "Sailor Moon", "description": "long blonde hair in odango, sailor scout uniform with pleated skirt", "eye_color": "blue", "hair_color": "blonde"},
|
| 24 |
+
{"name": "Hinata Hyuga", "series": "Naruto", "description": "dark blue hair, ninja outfit with lavender jacket and pants", "eye_color": "pale lavender", "hair_color": "dark blue"}
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
SETTINGS = [
|
| 28 |
+
"neon-lit office at midnight with hum of computers and scent of rain",
|
| 29 |
+
"gothic library filled with flickering candlelight and faded parchment scent",
|
| 30 |
+
"throne room bathed in warm golden light with velvet drapes",
|
| 31 |
+
"sterile operating room with bright surgical lights and soft beeping sounds",
|
| 32 |
+
"magical forest with glowing flora and gentle breeze rustling leaves"
|
| 33 |
+
]
|
| 34 |
+
|
| 35 |
+
ACTIVITIES = [
|
| 36 |
+
"reaching for a top-shelf file",
|
| 37 |
+
"arranging occult tomes on a desk",
|
| 38 |
+
"casting a subtle spell with glowing magical effects",
|
| 39 |
+
"serving coffee with graceful movements",
|
| 40 |
+
"walking confidently down a gothic hallway"
|
| 41 |
+
]
|
| 42 |
+
|
| 43 |
+
LINGERIE_COLORS = ["black", "red", "white", "navy blue", "deep burgundy"]
|
| 44 |
+
|
| 45 |
+
STOCKING_DETAILS = ["a delicate back seam", "intricate lace pattern", "classic fishnet design", "smooth satin finish", "subtle floral embroidery"]
|
| 46 |
+
|
| 47 |
+
HEEL_DETAILS = ["sharp stiletto heels", "elegant kitten heels", "strappy high heels", "sleek patent leather pumps", "classic pointed toe heels"]
|
| 48 |
+
|
| 49 |
+
POSES = ["confident stance, one hand on hip", "sitting casually on a desk", "leaning slightly forward", "standing with arms crossed", "walking with a playful smile"]
|
| 50 |
+
|
| 51 |
+
EXPRESSIONS = ["a knowing, seductive smile", "a confident, alluring gaze", "a playful smirk", "an intense, focused look", "a soft, inviting smile"]
|
| 52 |
+
|
| 53 |
+
def generate_prompt(character, setting, activity, lingerie_color, stocking_detail, heel_detail, pose, expression, prompt_num):
|
| 54 |
+
return f"""### Prompt {prompt_num}
|
| 55 |
+
**{character['name']}** (*{character['series']}*) is captured in a professional Ultra HD 16K (15360x8640) RAW photograph, set in **{setting}**, the ambiance filled with sensory elements. Her flawless cosplay features **{character['hair_color']} hair styled {character['description']}**, accented by **{character['eye_color']} eyes**, cascading over a **{lingerie_color} lace thong** and matching transparent lace bra. **Thigh-high stockings** with **{stocking_detail}** accentuate her legs, paired with **{heel_detail}**. The character is posed in a **{pose}**, her **{expression}** directed at the viewer. Shot from a **low-angle (worm’s eye view)** using a **Canon EOS R5 Cine RAW** with a **Canon RF 85mm f/1.2L USM lens**, the composition emphasizes her dominance and the sensual details of her lingerie. **ARRI SkyPanel S360-C lighting** creates soft, flattering illumination, enhancing realistic skin texture and fabric sheen, while **DaVinci Resolve color grading** adds vibrant, cinematic tones. The full vertical frame (knees to head) ensures no cropping, with perfect depth of field and subtle bokeh background.
|
| 56 |
+
Negative prompt keywords exclude cartoon, blurry, pixelated, low-resolution, watermark, noise, overexposed, underexposed, unnatural shadows, color banding, oversaturation, artificial textures, and all other disallowed artifacts."""
|
| 57 |
+
|
| 58 |
+
def chat_with_agent(user_message):
|
| 59 |
+
if user_message.strip().lower() == "ok":
|
| 60 |
+
prompts = []
|
| 61 |
+
selected_chars = random.sample(CHARACTER_FEMALES, 5)
|
| 62 |
+
for i, char in enumerate(selected_chars, start=1):
|
| 63 |
+
prompt = generate_prompt(
|
| 64 |
+
char,
|
| 65 |
+
random.choice(SETTINGS),
|
| 66 |
+
random.choice(ACTIVITIES),
|
| 67 |
+
random.choice(LINGERIE_COLORS),
|
| 68 |
+
random.choice(STOCKING_DETAILS),
|
| 69 |
+
random.choice(HEEL_DETAILS),
|
| 70 |
+
random.choice(POSES),
|
| 71 |
+
random.choice(EXPRESSIONS),
|
| 72 |
+
i
|
| 73 |
+
)
|
| 74 |
+
prompts.append(prompt)
|
| 75 |
+
return "\n\n".join(prompts)
|
| 76 |
+
else:
|
| 77 |
+
return "Please enter 'Ok' to generate 5 detailed cosplay prompts."
|
| 78 |
+
|
| 79 |
+
with gr.Blocks() as demo:
|
| 80 |
+
gr.Markdown("# Automatic Hyper-Realistic Cosplay Prompt Generator")
|
| 81 |
+
chatbot = gr.Chatbot()
|
| 82 |
+
msg = gr.Textbox(label="Type 'Ok' to generate 5 automatic prompts")
|
| 83 |
+
msg.submit(chat_with_agent, msg, chatbot)
|
| 84 |
+
msg.submit(lambda: "", None, msg) # Clear input after submit
|
| 85 |
+
|
| 86 |
+
if __name__ == "__main__":
|
| 87 |
+
demo.launch()
|
| 88 |
+
|