hoppiece commited on
Commit
2074013
·
1 Parent(s): 9bd0fd8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -15
app.py CHANGED
@@ -12,6 +12,8 @@ app_password = os.getenv("APP_PASSWORD")
12
  app_username = os.getenv("APP_USERNAME")
13
 
14
 
 
 
15
  PROMPT_1 = """\
16
  論文のアブストラクトに対し、そこから抽象的なアイコンやイメージを生成してスライドやポスターに使いたいです。生成には DALL・Eを使います。アブストラクトと、DALL・E の画像プロンプトを例として与えるので、最後に入力されるアブストラクトに対する画像プロンプトを考えて、1つ出力してください。プロンプト以外の文字は含まないでください
17
 
@@ -36,14 +38,13 @@ def generate(text, select_radio):
36
  temperature=0.0,
37
  )
38
  response = openai.Image.create(
39
- prompt="Draw an easy-to-read system configuration diagram under the following conditions Use only two colors, black and white. Use arrows and squares. This diagram is a pictogram. Write no alphabets. The following is the system configuration."
40
- + str(response["choices"][0]["message"]["content"]),
41
- n=1,
42
  size="256x256",
43
  )
44
  # icon
45
  # 後でプロンプトを変更する
46
- else:
47
  system_prompt = PROMPT_1
48
  response = openai.ChatCompletion.create(
49
  model="gpt-3.5-turbo-0613",
@@ -56,27 +57,25 @@ def generate(text, select_radio):
56
  )
57
  response = openai.Image.create(
58
  prompt=str(response["choices"][0]["message"]["content"]),
59
- n=1,
60
  size="256x256",
61
  )
62
- return response["data"][0]["url"]
63
-
 
64
 
65
- examples = [
66
- ["きのこの山"],
67
- ["たけのこの里"],
68
- ]
69
 
70
  demo = gr.Interface(
71
  fn=generate,
72
  inputs=[
73
- gr.components.Textbox(lines=5, label="Prompt"),
74
- gr.Radio(["icon", "pictogram"], label="radio"),
75
  ],
76
- outputs=gr.components.Image(type="filepath", label="Generated Image"),
77
  flagging_options=[],
78
- # examples=examples,
79
  )
80
 
81
  demo.launch(share=False, auth=(app_username, app_password))
82
  # https://www.gradio.app/docs/radio ラジオボタンの入力要素をリストで取得する
 
 
12
  app_username = os.getenv("APP_USERNAME")
13
 
14
 
15
+ NUM_OUTPUTS=4
16
+
17
  PROMPT_1 = """\
18
  論文のアブストラクトに対し、そこから抽象的なアイコンやイメージを生成してスライドやポスターに使いたいです。生成には DALL・Eを使います。アブストラクトと、DALL・E の画像プロンプトを例として与えるので、最後に入力されるアブストラクトに対する画像プロンプトを考えて、1つ出力してください。プロンプト以外の文字は含まないでください
19
 
 
38
  temperature=0.0,
39
  )
40
  response = openai.Image.create(
41
+ str(response["choices"][0]["message"]["content"]),
42
+ n=NUM_OUTPUTS,
 
43
  size="256x256",
44
  )
45
  # icon
46
  # 後でプロンプトを変更する
47
+ elif str(select_radio) == "icon":
48
  system_prompt = PROMPT_1
49
  response = openai.ChatCompletion.create(
50
  model="gpt-3.5-turbo-0613",
 
57
  )
58
  response = openai.Image.create(
59
  prompt=str(response["choices"][0]["message"]["content"]),
60
+ n=NUM_OUTPUTS,
61
  size="256x256",
62
  )
63
+ else:
64
+ raise gr.Error("Choose output type!")
65
+ return [response["data"][i]["url"] for i in range(NUM_OUTPUTS)]
66
 
 
 
 
 
67
 
68
  demo = gr.Interface(
69
  fn=generate,
70
  inputs=[
71
+ gr.components.Textbox(lines=5, label="Abstract of your paper"),
72
+ gr.Radio(["icon", "pictogram"], label="Output type", value="icon"),
73
  ],
74
+ outputs=[gr.components.Image(type="filepath", label="Generated Image") for _ in range(NUM_OUTPUTS)],
75
  flagging_options=[],
76
+ title="IdeaIllustrate"
77
  )
78
 
79
  demo.launch(share=False, auth=(app_username, app_password))
80
  # https://www.gradio.app/docs/radio ラジオボタンの入力要素をリストで取得する
81
+