Spaces:
Runtime error
Runtime error
deploy
Browse files
app.py
CHANGED
@@ -11,13 +11,46 @@ openai.api_key = os.getenv("API_KEY")
|
|
11 |
app_password = os.getenv("APP_PASSWORD")
|
12 |
app_username = os.getenv("APP_USERNAME")
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
examples = [
|
23 |
["きのこの山"],
|
@@ -26,10 +59,14 @@ examples = [
|
|
26 |
|
27 |
demo = gr.Interface(
|
28 |
fn=generate,
|
29 |
-
inputs=
|
|
|
|
|
|
|
30 |
outputs=gr.components.Image(type="filepath", label="Generated Image"),
|
31 |
flagging_options=[],
|
32 |
-
examples=examples
|
33 |
)
|
34 |
|
35 |
-
demo.launch(share=False, auth=(app_username, app_password))
|
|
|
|
11 |
app_password = os.getenv("APP_PASSWORD")
|
12 |
app_username = os.getenv("APP_USERNAME")
|
13 |
|
14 |
+
|
15 |
+
def generate(text, select_radio):
|
16 |
+
if select_radio.label is "pictogram":
|
17 |
+
system_prompt = "次の論文のAbstractを次の条件で英語で答えてください。修飾語彙をなるべく除外し、簡素にしてください。10 words 程度で要約してください。全体を満遍なく要約するのではなく、切り捨てる部分があってもよいので主要な部分のみを抽出してください。"
|
18 |
+
response = openai.ChatCompletion.create(
|
19 |
+
model="gpt-3.5-turbo-0613",
|
20 |
+
messages=[
|
21 |
+
{"role": "system", "content": system_prompt},
|
22 |
+
{"role": "user", "content": text},
|
23 |
+
],
|
24 |
+
frequency_penalty=0.0,
|
25 |
+
temperature=0.0,
|
26 |
+
)
|
27 |
+
response = openai.Image.create(
|
28 |
+
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."
|
29 |
+
+ str(response["choices"][0]["message"]["content"]),
|
30 |
+
n=1,
|
31 |
+
size="256x256",
|
32 |
+
)
|
33 |
+
# icon
|
34 |
+
# 後でプロンプトを変更する
|
35 |
+
else:
|
36 |
+
system_prompt = "論文のアブストラクトに対し、そこから抽象的なアイコンやイメージを生成してスライドやポスターに使いたいです。生成には DALL・Eを使います。アブストラクトと、DALL・E の画像プロンプトを例として与えるので、最後に入力されるアブストラクトに対する画像プロンプトを考えて、1つ出力してください。プロンプト以外の文字は含まないでください"
|
37 |
+
response = openai.ChatCompletion.create(
|
38 |
+
model="gpt-3.5-turbo-0613",
|
39 |
+
messages=[
|
40 |
+
{"role": "system", "content": system_prompt},
|
41 |
+
{"role": "user", "content": text},
|
42 |
+
],
|
43 |
+
frequency_penalty=0.0,
|
44 |
+
temperature=0.0,
|
45 |
+
)
|
46 |
+
response = openai.Image.create(
|
47 |
+
prompt="- A illustration for the slide. A robot washing papers with the buckets.An pictogram for the slide. A large number of documents are piled up. A robot is sorting through them."
|
48 |
+
+ str(response["choices"][0]["message"]["content"]),
|
49 |
+
n=1,
|
50 |
+
size="256x256",
|
51 |
+
)
|
52 |
+
return response["data"][0]["url"]
|
53 |
+
|
54 |
|
55 |
examples = [
|
56 |
["きのこの山"],
|
|
|
59 |
|
60 |
demo = gr.Interface(
|
61 |
fn=generate,
|
62 |
+
inputs=[
|
63 |
+
gr.components.Textbox(lines=5, label="Prompt"),
|
64 |
+
gr.Radio(["icon", "pictogram"], label="radio"),
|
65 |
+
],
|
66 |
outputs=gr.components.Image(type="filepath", label="Generated Image"),
|
67 |
flagging_options=[],
|
68 |
+
# examples=examples,
|
69 |
)
|
70 |
|
71 |
+
demo.launch(share=False, auth=(app_username, app_password))
|
72 |
+
# https://www.gradio.app/docs/radio ラジオボタンの入力要素をリストで取得する
|