Spaces:
Sleeping
Sleeping
Update main.py
Browse files8 unmodified lines9101112131414 unmodified lines2930313233343536373839404139 unmodified lines8182838485868788898 unmodified linesimport osimport socketimport time#--------------------------------------------------- Definizione Server FAST API ------------------------------------------------------app = FastAPI()14 unmodified linestop_p: float = 0.95repetition_penalty: float = 1.0class InputImage(BaseModel):input: strnegativePrompt: str = ''steps: int = 30cfg: int = 7seed: int = -1class PostSpazio(BaseModel):nomeSpazio: strinput: str = ''39 unmodified lines#--------------------------------------------------- Generazione IMMAGINE ------------------------------------------------------@app.post("/Immagine")def generate_image(request: Request, input_data: InputImage):client = Client("https://openskyml-fast-sdxl-stable-diffusion-xl.hf.space/--replicas/545b5tw7n/")max_attempts = 20attempt = 0while attempt < max_attempts:8 unmodified lines910111213141514 unmodified lines30313233343539 unmodified lines757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881898 unmodified linesimport osimport socketimport timefrom enum import Enum#--------------------------------------------------- Definizione Server FAST API ------------------------------------------------------app = FastAPI()14 unmodified linestop_p: float = 0.95repetition_penalty: float = 1.0class PostSpazio(BaseModel):nomeSpazio: strinput: str = ''39 unmodified lines#--------------------------------------------------- Generazione IMMAGINE ------------------------------------------------------style_image = {"PROFESSIONAL-PHOTO": {"descrizione": "Professional photo {prompt} . Vivid colors, Mirrorless, 35mm lens, f/1.8 aperture, ISO 100, natural daylight","negativePrompt": "out of frame, lowres, text, error, cropped, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, out of frame, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck, username, watermark, signature"},"CINEMATIC-PHOTO": {"descrizione": "cinematic photo {prompt} . 35mm photograph, film, bokeh, professional, 4k, highly detailed","negativePrompt": "drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly"},"CINEMATIC-PORTRAIT": {"descrizione": "cinematic portrait {prompt} 8k, ultra realistic, good vibes, vibrant","negativePrompt": "drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly"},"LINE-ART-DRAWING": {"descrizione": "line art drawing {prompt} . professional, sleek, modern, minimalist, graphic, line art, vector graphics","negativePrompt": "anime, photorealistic, 35mm film, deformed, glitch, blurry, noisy, off-center, deformed, cross-eyed, closed eyes, bad anatomy, ugly, disfigured, mutated, realism, realistic, impressionism, expressionism, oil, acrylic"},"COMIC": {"descrizione": "comic {prompt} . graphic illustration, comic art, graphic novel art, vibrant, highly detailed","negativePrompt": "photograph, deformed, glitch, noisy, realistic, stock photo"},"ADVERTISING-POSTER-STYLE": {"descrizione": "advertising poster style {prompt} . Professional, modern, product-focused, commercial, eye-catching, highly detailed","negativePrompt": "noisy, blurry, amateurish, sloppy, unattractive"},"RETAIL-PACKAGING-STYLE": {"descrizione": "retail packaging style {prompt} . vibrant, enticing, commercial, product-focused, eye-catching, professional, highly detailed","negativePrompt": "noisy, blurry, amateurish, sloppy, unattractive"},"GRAFFITI-STYLE": {"descrizione": "graffiti style {prompt} . street art, vibrant, urban, detailed, tag, mural","negativePrompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic"},"POP-ART-STYLE": {"descrizione": "pop Art style {prompt} . bright colors, bold outlines, popular culture themes, ironic or kitsch","negativePrompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, minimalist"},"ISOMETRIC-STYLE": {"descrizione": "isometric style {prompt} . vibrant, beautiful, crisp, detailed, ultra detailed, intricate","negativePrompt": "deformed, mutated, ugly, disfigured, blur, blurry, noise, noisy, realistic, photographic"},"LOW-POLY-STYLE": {"descrizione": "low-poly style {prompt}. ambient occlusion, low-poly game art, polygon mesh, jagged, blocky, wireframe edges, centered composition","negativePrompt": "noisy, sloppy, messy, grainy, highly detailed, ultra textured, photo"},"CLAYMATION-STYLE": {"descrizione": "claymation style {prompt} . sculpture, clay art, centered composition, play-doh","negativePrompt": ""},"PROFESSIONAL-3D-MODEL": {"descrizione": "professional 3d model {prompt} . octane render, highly detailed, volumetric, dramatic lighting","negativePrompt": "ugly, deformed, noisy, low poly, blurry, painting"},"ANIME-ARTWORK": {"descrizione": "anime artwork {prompt} . anime style, key visual, vibrant, studio anime, highly detailed","negativePrompt": "photo, deformed, black and white, realism, disfigured, low contrast"},"ETHEREAL-FANTASY-CONCEPT-ART": {"descrizione": "ethereal fantasy concept art of {prompt} . magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy","negativePrompt": "photographic, realistic, realism, 35mm film, dslr, cropped, frame, text, deformed, glitch, noise, noisy, off-center, deformed, cross-eyed, closed eyes, bad anatomy, ugly, disfigured, sloppy, duplicate, mutated, black and white"},"CYBERNETIC-STYLE": {"descrizione": "cybernetic style {prompt} . futuristic, technological, cybernetic enhancements, robotics, artificial intelligence themes","negativePrompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, historical, medieval"},"FUTURISTIC-STYLE": {"descrizione": "futuristic style {prompt} . sleek, modern, ultramodern, high tech, detailed","negativePrompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, vintage, antique"},"SCI-FI-STYLE": {"descrizione": "sci-fi style {prompt} . futuristic, technological, alien worlds, space themes, advanced civilizations","negativePrompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, historical, medieval"},"DIGITAL-ART": {"descrizione": "Digital Art {prompt} . vibrant, cute, digital, handmade","negativePrompt": ""},"SIMPLE-LOGO": {"descrizione": "Minimalist Logo {prompt} . material design, primary colors, stylized, minimalist","negativePrompt": "3D, high detail, noise, grainy, blurry, painting, drawing, photo, disfigured"},"MINIMALISTIC-LOGO": {"descrizione": "Ultra-minimalist Material Design logo for a BRAND: {prompt} . simple, few colors, clean lines, minimal details, modern color palette, no shadows","negativePrompt": "3D, high detail, noise, grainy, blurry, painting, drawing, photo, disfigured"}}def create_style_enum(style_image):return Enum("StyleEnum", [(style, style) for style in style_image.keys()])enum_styles = create_style_enum(style_image)class InputImage(BaseModel):input: strnegativePrompt: str = ''style: Enum = Enum("StyleEnum", [(style, style) for style in style_image.keys()])steps: int = 30cfg: int = 7seed: int = -1@app.post("/Immagine")def generate_image(request: Request, input_data: InputImage):client = Client("https://openskyml-fast-sdxl-stable-diffusion-xl.hf.space/--replicas/545b5tw7n/")if input_data.style:if input_data.style in style_image:style_info = style_image[input_data.style]input_data.input = style_info["descrizione"].format(prompt=input_data.input)input_data.negativePrompt = style_info["negativePrompt"]max_attempts = 20attempt = 0while attempt < max_attempts:
main.py+107-7