Spaces:
Runtime error
Runtime error
| import os | |
| import gradio as gr | |
| import requests | |
| openai_key = os.getenv("OPENAI_API_KEY") | |
| class Logo: | |
| def __init__(self,name,slogan, industry, color_scheme, font_style) -> None: | |
| self.name = name | |
| self.slogan = slogan | |
| self.industry = industry | |
| self.color_scheme = color_scheme | |
| self.font_style = font_style | |
| def build_prompt(desc) -> str: | |
| return f""" | |
| I would like you to act as an Logo designer. | |
| Create a logo for a company called '{desc.name}',the logo design does not need to include the name. | |
| The company specializes in {desc.industry} research and development. | |
| The logo should convey a sense of {desc.color_scheme}, {desc.font_style}, | |
| and the microscopic world of {desc.industry}. | |
| Use a color scheme that represents {desc.color_scheme}. | |
| """ | |
| def ganerate(logo_name, slogan, industry, color_scheme, font_style): | |
| n = 1 | |
| logo = Logo(logo_name, slogan, industry, color_scheme, font_style) | |
| prompt = build_prompt(logo) | |
| size="256x256" | |
| data = {"n": n, "prompt": prompt, "size": size} | |
| headers = {"Content-Type": "application/json","Authorization": f"""Bearer {openai_key}"""} | |
| result = requests.post("https://api.openai.com/v1/images/generations",json=data,headers=headers) | |
| return result.json()["data"][0]["url"] | |
| color_schemes=["Warm", "Cold", "Contrast", "Pastel", "Greyscale", "Gradient"] | |
| font_tyles=["Modern", "Elegant", "Slab", "Handwritten", "Playful", "Futuristic"] | |
| industries=["Travel", "Sport Fitness", "Retail", "Religious", | |
| "Real Estate", "Legal", "Internet", "Technology", "Home Family", | |
| "Events", "Medical Dental", "Restaurant", "Finance", "Nonprofit", | |
| "Entertainment", "Construction", "Education", "Beauty Spa", "Automotive", | |
| "Animals Pets", "Others"] | |
| iface = gr.Interface( | |
| fn=ganerate, | |
| inputs=[ | |
| gr.Textbox(placeholder="Logo Name", label="Logo name"), | |
| gr.Textbox(placeholder="Slogan (optional)", label="Slogan"), | |
| gr.Radio(industries, label="Industry", info="Please Select A Industry"), | |
| gr.Radio(color_schemes, label="Color scheme", info="Select color schemes that matches your brand"), | |
| gr.Radio(font_tyles,label="Font style", info="Select font styles that you like") | |
| ], | |
| outputs="image") | |
| iface.launch(server_name="0.0.0.0") |