Amovane commited on
Commit
1251646
·
1 Parent(s): 82d2b4d

optimize: improve prompt

Browse files
app.ipynb CHANGED
@@ -35,14 +35,14 @@
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
  ]
@@ -50,7 +50,7 @@
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>"
@@ -63,9 +63,31 @@
63
  "data": {
64
  "text/plain": []
65
  },
66
- "execution_count": 9,
67
  "metadata": {},
68
  "output_type": "execute_result"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  }
70
  ],
71
  "source": [
@@ -74,9 +96,29 @@
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",
@@ -84,7 +126,7 @@
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",
 
35
  },
36
  {
37
  "cell_type": "code",
38
+ "execution_count": 15,
39
  "metadata": {},
40
  "outputs": [
41
  {
42
  "name": "stdout",
43
  "output_type": "stream",
44
  "text": [
45
+ "Running on local URL: http://127.0.0.1:7873\n",
46
  "\n",
47
  "To create a public link, set `share=True` in `launch()`.\n"
48
  ]
 
50
  {
51
  "data": {
52
  "text/html": [
53
+ "<div><iframe src=\"http://127.0.0.1:7873/\" 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>"
 
63
  "data": {
64
  "text/plain": []
65
  },
66
+ "execution_count": 15,
67
  "metadata": {},
68
  "output_type": "execute_result"
69
+ },
70
+ {
71
+ "name": "stdout",
72
+ "output_type": "stream",
73
+ "text": [
74
+ "prompt \n",
75
+ " I would like you to act as an SVG designer. I will ask you to create images, and you will come up with SVG code for the image,\n",
76
+ " Create a logo for a company called 'Shareverse' \n",
77
+ " The company specializes in Technology research and development. \n",
78
+ " The logo should convey a sense of Contrast, Elegant, \n",
79
+ " and the microscopic world of Technology. \n",
80
+ " Use a color scheme that represents Contrast. \n",
81
+ " \n",
82
+ "prompt \n",
83
+ " I would like you to act as an SVG designer. I will ask you to create images, and you will come up with SVG code for the image,\n",
84
+ " Create a logo for a company called 'Shareverse' \n",
85
+ " The company specializes in Beauty Spa research and development. \n",
86
+ " The logo should convey a sense of Cold, Elegant, \n",
87
+ " and the microscopic world of Beauty Spa. \n",
88
+ " Use a color scheme that represents Cold. \n",
89
+ " \n"
90
+ ]
91
  }
92
  ],
93
  "source": [
 
96
  "import requests\n",
97
  "%env OPENAI_KEY\n",
98
  "openai_key = os.getenv(\"OPENAI_KEY\")\n",
99
+ "\n",
100
+ "class Logo:\n",
101
+ " def __init__(self,name,slogan, industry, color_scheme, font_style) -> None:\n",
102
+ " self.name = name\n",
103
+ " self.slogan = slogan\n",
104
+ " self.industry = industry\n",
105
+ " self.color_scheme = color_scheme\n",
106
+ " self.font_style = font_style\n",
107
+ "\n",
108
+ "def build_prompt(desc) -> str:\n",
109
+ " return f\"\"\"\n",
110
+ " I would like you to act as an SVG designer. I will ask you to create images, and you will come up with SVG code for the image,\n",
111
+ " Create a logo for a company called '{desc.name}' \n",
112
+ " The company specializes in {desc.industry} research and development. \n",
113
+ " The logo should convey a sense of {desc.color_scheme}, {desc.font_style}, \n",
114
+ " and the microscopic world of {desc.industry}. \n",
115
+ " Use a color scheme that represents {desc.color_scheme}. \n",
116
+ " \"\"\"\n",
117
+ "\n",
118
+ "def ganerate(logo_name, slogan, industry, color_scheme, font_style):\n",
119
  " n = 1\n",
120
+ " logo = Logo(logo_name, slogan, industry, color_scheme, font_style)\n",
121
+ " prompt = build_prompt(logo)\n",
122
  " size=\"256x256\"\n",
123
  " data = {\"n\": n, \"prompt\": prompt, \"size\": size}\n",
124
  " headers = {\"Content-Type\": \"application/json\",\"Authorization\": f\"\"\"Bearer {openai_key}\"\"\"}\n",
 
126
  " return result.json()[\"data\"][0][\"url\"]\n",
127
  "\n",
128
  "iface = gr.Interface(\n",
129
+ " fn=ganerate, \n",
130
  " inputs=[\n",
131
  " gr.Textbox(placeholder=\"Logo Name\", label=\"Logo name\"),\n",
132
  " gr.Textbox(placeholder=\"Slogan (optional)\", label=\"Slogan\"),\n",
app.py CHANGED
@@ -2,9 +2,29 @@ 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}"""}
@@ -12,7 +32,7 @@ def prompt_builder(logo_name, slogan, industry, color_scheme, font_style):
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"),
 
2
  import gradio as gr
3
  import requests
4
  openai_key = os.getenv("OPENAI_KEY")
5
+
6
+ class Logo:
7
+ def __init__(self,name,slogan, industry, color_scheme, font_style) -> None:
8
+ self.name = name
9
+ self.slogan = slogan
10
+ self.industry = industry
11
+ self.color_scheme = color_scheme
12
+ self.font_style = font_style
13
+
14
+ def build_prompt(desc) -> str:
15
+ return f"""
16
+ I would like you to act as an SVG designer. I will ask you to create images, and you will come up with SVG code for the image,
17
+ Create a logo for a company called '{desc.name}'
18
+ The company specializes in {desc.industry} research and development.
19
+ The logo should convey a sense of {desc.color_scheme}, {desc.font_style},
20
+ and the microscopic world of {desc.industry}.
21
+ Use a color scheme that represents {desc.color_scheme}.
22
+ """
23
+
24
+ def ganerate(logo_name, slogan, industry, color_scheme, font_style):
25
  n = 1
26
+ logo = Logo(logo_name, slogan, industry, color_scheme, font_style)
27
+ prompt = build_prompt(logo)
28
  size="256x256"
29
  data = {"n": n, "prompt": prompt, "size": size}
30
  headers = {"Content-Type": "application/json","Authorization": f"""Bearer {openai_key}"""}
 
32
  return result.json()["data"][0]["url"]
33
 
34
  iface = gr.Interface(
35
+ fn=ganerate,
36
  inputs=[
37
  gr.Textbox(placeholder="Logo Name", label="Logo name"),
38
  gr.Textbox(placeholder="Slogan (optional)", label="Slogan"),
flagged/log.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ Logo name,Slogan,Industry,Color scheme,Font style,output,flag,username,timestamp
2
+ Shareverse,,Technology,Cold,Elegant,/Users/ny0/workspace/ailogo/flagged/output/1516953fb06afb7de691ab6f2625e7b75c0081ec/tmpr238pvma.txt,,,2023-09-12 01:32:19.153945
flagged/output/1516953fb06afb7de691ab6f2625e7b75c0081ec/tmpr238pvma.txt ADDED
Binary file (197 kB). View file