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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 26,
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"outputs": [
|
| 8 |
+
{
|
| 9 |
+
"name": "stderr",
|
| 10 |
+
"output_type": "stream",
|
| 11 |
+
"text": [
|
| 12 |
+
"/Users/ny0/workspace/ailogo/venv/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
| 13 |
+
" from .autonotebook import tqdm as notebook_tqdm\n"
|
| 14 |
+
]
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"name": "stdout",
|
| 18 |
+
"output_type": "stream",
|
| 19 |
+
"text": [
|
| 20 |
+
"Loaded as API: https://passant-labs-ailogo.hf.space/ ✔\n",
|
| 21 |
+
"Hello Howdy!!!\n"
|
| 22 |
+
]
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"source": [
|
| 26 |
+
"from gradio_client import Client\n",
|
| 27 |
+
"\n",
|
| 28 |
+
"client = Client(\"https://passant-labs-ailogo.hf.space/\")\n",
|
| 29 |
+
"result = client.predict(\n",
|
| 30 |
+
"\t\t\t\t\"Howdy!\",\n",
|
| 31 |
+
"\t\t\t\tapi_name=\"/predict\"\n",
|
| 32 |
+
")\n",
|
| 33 |
+
"print(result)\n"
|
| 34 |
+
]
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
"cell_type": "code",
|
| 38 |
+
"execution_count": 9,
|
| 39 |
+
"metadata": {},
|
| 40 |
+
"outputs": [
|
| 41 |
+
{
|
| 42 |
+
"name": "stdout",
|
| 43 |
+
"output_type": "stream",
|
| 44 |
+
"text": [
|
| 45 |
+
"Running on local URL: http://127.0.0.1:7867\n",
|
| 46 |
+
"\n",
|
| 47 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
| 48 |
+
]
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"data": {
|
| 52 |
+
"text/html": [
|
| 53 |
+
"<div><iframe src=\"http://127.0.0.1:7867/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 54 |
+
],
|
| 55 |
+
"text/plain": [
|
| 56 |
+
"<IPython.core.display.HTML object>"
|
| 57 |
+
]
|
| 58 |
+
},
|
| 59 |
+
"metadata": {},
|
| 60 |
+
"output_type": "display_data"
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"data": {
|
| 64 |
+
"text/plain": []
|
| 65 |
+
},
|
| 66 |
+
"execution_count": 9,
|
| 67 |
+
"metadata": {},
|
| 68 |
+
"output_type": "execute_result"
|
| 69 |
+
}
|
| 70 |
+
],
|
| 71 |
+
"source": [
|
| 72 |
+
"import os\n",
|
| 73 |
+
"import gradio as gr\n",
|
| 74 |
+
"import requests\n",
|
| 75 |
+
"%env OPENAI_KEY\n",
|
| 76 |
+
"openai_key = os.getenv(\"OPENAI_KEY\")\n",
|
| 77 |
+
"def prompt_builder(logo_name, slogan, industry, color_scheme, font_style):\n",
|
| 78 |
+
" n = 1\n",
|
| 79 |
+
" prompt = f\"\"\"Please generate a logo which name is {logo_name} {(\", slogan is \"+slogan) if slogan else \"\"}, industry is {industry}, color scheme is {color_scheme}, font style is {font_style}\"\"\"\n",
|
| 80 |
+
" size=\"256x256\"\n",
|
| 81 |
+
" data = {\"n\": n, \"prompt\": prompt, \"size\": size}\n",
|
| 82 |
+
" headers = {\"Content-Type\": \"application/json\",\"Authorization\": f\"\"\"Bearer {openai_key}\"\"\"}\n",
|
| 83 |
+
" result = requests.post(\"https://api.openai.com/v1/images/generations\",json=data,headers=headers)\n",
|
| 84 |
+
" return result.json()[\"data\"][0][\"url\"]\n",
|
| 85 |
+
"\n",
|
| 86 |
+
"iface = gr.Interface(\n",
|
| 87 |
+
" fn=prompt_builder, \n",
|
| 88 |
+
" inputs=[\n",
|
| 89 |
+
" gr.Textbox(placeholder=\"Logo Name\", label=\"Logo name\"),\n",
|
| 90 |
+
" gr.Textbox(placeholder=\"Slogan (optional)\", label=\"Slogan\"),\n",
|
| 91 |
+
" gr.Radio([\"Travel\", \"Sport Fitness\", \"Retail\", \"Religious\", \"Real Estate\", \n",
|
| 92 |
+
" \"Legal\", \"Internet\", \"Technology\", \"Home Family\", \"Events\"\n",
|
| 93 |
+
" \"Medical Dental\", \"Restaurant\", \"Finance\", \"Nonprofit\", \n",
|
| 94 |
+
" \"Entertainment\", \"Construction\", \"Education\", \"Beauty Spa\", \"Automotive\", \"Animals Pets\", \"Others\"], label=\"Industry\", info=\"Please Select A Industry\"),\n",
|
| 95 |
+
" gr.Radio([\"Warm\", \"Cold\", \"Contrast\", \"Pastel\", \"Greyscale\", \"Gradient\"], label=\"Color scheme\", info=\"Select color schemes that matches your brand\"),\n",
|
| 96 |
+
" gr.Radio([\"Modern\", \"Elegant\", \"Slab\", \"Handwritten\", \"Playful\", \"Futuristic\"],label=\"Font style\", info=\"Select font styles that you like\")\n",
|
| 97 |
+
" ], \n",
|
| 98 |
+
" outputs=\"image\")\n",
|
| 99 |
+
"iface.launch()\n",
|
| 100 |
+
"\n"
|
| 101 |
+
]
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"cell_type": "code",
|
| 105 |
+
"execution_count": 2,
|
| 106 |
+
"metadata": {},
|
| 107 |
+
"outputs": [
|
| 108 |
+
{
|
| 109 |
+
"data": {
|
| 110 |
+
"text/plain": [
|
| 111 |
+
"'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'"
|
| 112 |
+
]
|
| 113 |
+
},
|
| 114 |
+
"execution_count": 2,
|
| 115 |
+
"metadata": {},
|
| 116 |
+
"output_type": "execute_result"
|
| 117 |
+
},
|
| 118 |
+
{
|
| 119 |
+
"name": "stdout",
|
| 120 |
+
"output_type": "stream",
|
| 121 |
+
"text": [
|
| 122 |
+
"key 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\n",
|
| 123 |
+
"result, <Response [200]>\n"
|
| 124 |
+
]
|
| 125 |
+
}
|
| 126 |
+
],
|
| 127 |
+
"source": []
|
| 128 |
+
}
|
| 129 |
+
],
|
| 130 |
+
"metadata": {
|
| 131 |
+
"kernelspec": {
|
| 132 |
+
"display_name": "Python 3",
|
| 133 |
+
"language": "python",
|
| 134 |
+
"name": "python3"
|
| 135 |
+
},
|
| 136 |
+
"language_info": {
|
| 137 |
+
"codemirror_mode": {
|
| 138 |
+
"name": "ipython",
|
| 139 |
+
"version": 3
|
| 140 |
+
},
|
| 141 |
+
"file_extension": ".py",
|
| 142 |
+
"mimetype": "text/x-python",
|
| 143 |
+
"name": "python",
|
| 144 |
+
"nbconvert_exporter": "python",
|
| 145 |
+
"pygments_lexer": "ipython3",
|
| 146 |
+
"version": "3.11.2"
|
| 147 |
+
},
|
| 148 |
+
"orig_nbformat": 4
|
| 149 |
+
},
|
| 150 |
+
"nbformat": 4,
|
| 151 |
+
"nbformat_minor": 2
|
| 152 |
+
}
|
app.py
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
iface.launch()
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
import requests
|
| 4 |
+
openai_key = os.getenv("OPENAI_KEY")
|
| 5 |
+
def prompt_builder(logo_name, slogan, industry, color_scheme, font_style):
|
| 6 |
+
n = 1
|
| 7 |
+
prompt = f"""Please generate a logo which name is {logo_name} {(", slogan is "+slogan) if slogan else ""}, industry is {industry}, color scheme is {color_scheme}, font style is {font_style}"""
|
| 8 |
+
size="256x256"
|
| 9 |
+
data = {"n": n, "prompt": prompt, "size": size}
|
| 10 |
+
headers = {"Content-Type": "application/json","Authorization": f"""Bearer {openai_key}"""}
|
| 11 |
+
result = requests.post("https://api.openai.com/v1/images/generations",json=data,headers=headers)
|
| 12 |
+
return result.json()["data"][0]["url"]
|
| 13 |
|
| 14 |
+
iface = gr.Interface(
|
| 15 |
+
fn=prompt_builder,
|
| 16 |
+
inputs=[
|
| 17 |
+
gr.Textbox(placeholder="Logo Name", label="Logo name"),
|
| 18 |
+
gr.Textbox(placeholder="Slogan (optional)", label="Slogan"),
|
| 19 |
+
gr.Radio(["Travel", "Sport Fitness", "Retail", "Religious", "Real Estate",
|
| 20 |
+
"Legal", "Internet", "Technology", "Home Family", "Events"
|
| 21 |
+
"Medical Dental", "Restaurant", "Finance", "Nonprofit",
|
| 22 |
+
"Entertainment", "Construction", "Education", "Beauty Spa", "Automotive", "Animals Pets", "Others"], label="Industry", info="Please Select A Industry"),
|
| 23 |
+
gr.Radio(["Warm", "Cold", "Contrast", "Pastel", "Greyscale", "Gradient"], label="Color scheme", info="Select color schemes that matches your brand"),
|
| 24 |
+
gr.Radio(["Modern", "Elegant", "Slab", "Handwritten", "Playful", "Futuristic"],label="Font style", info="Select font styles that you like")
|
| 25 |
+
],
|
| 26 |
+
outputs="image")
|
| 27 |
iface.launch()
|