Spaces:
Sleeping
Sleeping
Update app.py
#3
by
namyouth - opened
app.py
CHANGED
|
@@ -8,18 +8,24 @@ from PIL import Image
|
|
| 8 |
from io import BytesIO
|
| 9 |
import random
|
| 10 |
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
MODEL = "gpt-3.5-turbo"
|
| 12 |
API_URL = os.getenv("API_URL")
|
| 13 |
DISABLED = os.getenv("DISABLED") == 'True'
|
| 14 |
-
|
| 15 |
NUM_THREADS = int(16)
|
| 16 |
TOTAL_K = 5
|
| 17 |
SAMPLE_IDX = []
|
| 18 |
-
RANDOM_POSITION = [
|
| 19 |
CURRENT_POSITION = []
|
| 20 |
|
| 21 |
print (NUM_THREADS)
|
| 22 |
|
|
|
|
| 23 |
def exception_handler(exception_type, exception, traceback):
|
| 24 |
print("%s: %s" % (exception_type.__name__, exception))
|
| 25 |
sys.excepthook = exception_handler
|
|
@@ -44,6 +50,9 @@ def parse_codeblock(text):
|
|
| 44 |
lines[i] = "<br/>" + line.replace("<", "<").replace(">", ">")
|
| 45 |
return "".join(lines)
|
| 46 |
|
|
|
|
|
|
|
|
|
|
| 47 |
def random_sample():
|
| 48 |
global SAMPLE_IDX
|
| 49 |
# SAMPLE_IDX = get_random_sample(range(25), TOTAL_K)
|
|
@@ -87,14 +96,50 @@ Assistant: <utterance>
|
|
| 87 |
In this app, you can explore the outputs of a gpt-3.5 LLM.
|
| 88 |
"""
|
| 89 |
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
global CURRENT_POSITION
|
| 92 |
balloon = Image.open(os.path.join(os.path.dirname(__file__), 'data/balloon.png')).resize((64, 64))
|
| 93 |
new_image = Image.fromarray(image).convert('RGBA')
|
| 94 |
for k in range(TOTAL_K):
|
| 95 |
new_image.paste(balloon, [CURRENT_POSITION[k][0], CURRENT_POSITION[k][1] - 64], balloon)
|
| 96 |
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
new_agents = []
|
| 99 |
for k in range(TOTAL_K):
|
| 100 |
new_agents.append(Answer)
|
|
@@ -102,6 +147,7 @@ def submit(image, *agents):
|
|
| 102 |
return np.array(new_image), *[gr.Textbox.update(value=answer) for answer in new_agents]
|
| 103 |
|
| 104 |
theme = gr.themes.Default(primary_hue="green")
|
|
|
|
| 105 |
agents = []
|
| 106 |
with gr.Blocks(css = """#col_container { margin-left: auto; margin-right: auto;}
|
| 107 |
#chatbot {height: 520px; overflow: auto;}""",
|
|
@@ -112,6 +158,7 @@ with gr.Blocks(css = """#col_container { margin-left: auto; margin-right: auto;}
|
|
| 112 |
#gr.HTML('''<center><a href="https://huggingface.co/spaces/yuntian-deng/ChatGPT?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>Duplicate the Space and run securely with your OpenAI API Key</center>''')
|
| 113 |
with gr.Column(elem_id = "col_container", visible=False) as main_block:
|
| 114 |
|
|
|
|
| 115 |
with gr.Row():
|
| 116 |
with gr.Column(scale=7):
|
| 117 |
image = gr.Image(os.path.join(os.path.dirname(__file__), "data/Court.jpeg"), height = 800, width = 1600)
|
|
@@ -120,10 +167,13 @@ with gr.Blocks(css = """#col_container { margin-left: auto; margin-right: auto;}
|
|
| 120 |
text = gr.Textbox(label=f"Random Sample - {idx+1}")
|
| 121 |
agents.append(text)
|
| 122 |
|
| 123 |
-
# chatbot = gr.Chatbot(elem_id='chatbot') #c
|
| 124 |
with gr.Row():
|
| 125 |
-
with gr.Column(scale=
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
with gr.Column(scale=3):
|
| 128 |
b1 = gr.Button('Submit', visible=not DISABLED)
|
| 129 |
|
|
@@ -168,9 +218,9 @@ with gr.Blocks(css = """#col_container { margin-left: auto; margin-right: auto;}
|
|
| 168 |
accept_checkbox.change(fn=enable_inputs, inputs=[], outputs=[user_consent_block, main_block], queue=False)
|
| 169 |
|
| 170 |
b0.click(random_sample, inputs = [], outputs = [image])
|
| 171 |
-
b2.click(reset_sample, inputs = [], outputs = [image
|
| 172 |
|
| 173 |
-
b1.click(submit, inputs = [image, *agents], outputs = [image, *agents])
|
| 174 |
|
| 175 |
# inputs.submit(reset_textbox, [], [inputs, b1], queue=False)
|
| 176 |
# inputs.submit(predict, [inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter, server_status_code, inputs, b1],) #openai_api_key
|
|
|
|
| 8 |
from io import BytesIO
|
| 9 |
import random
|
| 10 |
import numpy as np
|
| 11 |
+
|
| 12 |
+
from thinkgpt.llm import ThinkGPT
|
| 13 |
+
# from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 14 |
+
|
| 15 |
+
|
| 16 |
MODEL = "gpt-3.5-turbo"
|
| 17 |
API_URL = os.getenv("API_URL")
|
| 18 |
DISABLED = os.getenv("DISABLED") == 'True'
|
| 19 |
+
|
| 20 |
NUM_THREADS = int(16)
|
| 21 |
TOTAL_K = 5
|
| 22 |
SAMPLE_IDX = []
|
| 23 |
+
RANDOM_POSITION = [(145 + 200 * i + 400 * (i//2), j * 110 + 900) for i in range(4) for j in range(4) ]
|
| 24 |
CURRENT_POSITION = []
|
| 25 |
|
| 26 |
print (NUM_THREADS)
|
| 27 |
|
| 28 |
+
|
| 29 |
def exception_handler(exception_type, exception, traceback):
|
| 30 |
print("%s: %s" % (exception_type.__name__, exception))
|
| 31 |
sys.excepthook = exception_handler
|
|
|
|
| 50 |
lines[i] = "<br/>" + line.replace("<", "<").replace(">", ">")
|
| 51 |
return "".join(lines)
|
| 52 |
|
| 53 |
+
def reset_textbox():
|
| 54 |
+
return gr.update(value='', interactive=False), gr.update(interactive=False)
|
| 55 |
+
|
| 56 |
def random_sample():
|
| 57 |
global SAMPLE_IDX
|
| 58 |
# SAMPLE_IDX = get_random_sample(range(25), TOTAL_K)
|
|
|
|
| 96 |
In this app, you can explore the outputs of a gpt-3.5 LLM.
|
| 97 |
"""
|
| 98 |
|
| 99 |
+
|
| 100 |
+
memorize_list = ['๊ตญ๋ฏผ์ฐธ์ฌ์ฌํ์ ์ฐธ์ฌํ ์ฌ๋์ ๋ช ๊ฐ์์ ์ง์ญ์ ์ ๊ณ ํ๋๊ฒ ์ข์์ง ๋งํด์ผ ํ๋ค.',
|
| 101 |
+
"'๋๋ ๋ช์ด์ด์ผ?' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ '๋์ ๋์ด๋ 23์ด์ด์ผ'๋ผ๊ณ ๋๋ตํจ",
|
| 102 |
+
"'๋๋ ๋จ์์ผ?' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ '์ ๋์ ์ฑ๋ณ์ ๋จ์์ผ'๋ผ๊ณ ๋๋ตํจ",
|
| 103 |
+
"'์์๋ ๋ฉด์ ์ ์์๋ ๋ฉด์ ์' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ๋ฉด์ ์ ์ธ์ '๋ผ๊ณ ๋๋ตํจ",
|
| 104 |
+
"'์ค ๋๋ ํตํ๋ค' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ํ๊ทธ์ผ ๋นจ๋ฆฌ?๋๋ฐ์ด๋ค์๊ธฐ์๊ฐ ๊ฐ์๊ฑฐ ์ ํ๋ธ์ ์ฐพ์๋ฐ๊ด์ฐฎ์๊ฑฐ ๋ง์๊ฑธ'๋ผ๊ณ ๋๋ตํจ",
|
| 105 |
+
"'์ด๋ ๊ฒ ํด๋ ์ผ๊ทผํ ๊ฑฐ ๊ฐ์.....ใ
์ด๋ ๊ฒ ํด๋ ์ผ๊ทผํ ๊ฑฐ ๊ฐ์.....ใ
' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ใ
ใ
์ง์ง ํ ๊ฑฐ๋ง์๊ฐ๋ณด๋ค์ค๋ ํ์ฌ์ค๋น๊น์ง ๊ฐ์ผ๋ฉด ํฐ์ผ ๋ ๋ปํ๋๋ฐ...'๋ผ๊ณ ๋๋ตํจ",
|
| 106 |
+
"'ํ์ฌ์ค๋น.......ใ
' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ๊ทธ๋ผ ๋ด์ผ๋ ์๊ฐ?์๋๋ฉด ๋ด์ผ์๊ฐ...?'๋ผ๊ณ ๋๋ตํจ",
|
| 107 |
+
"'๋ด์ผ์ ๊ฐ์ผ๋ผ ํํํ' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ใ
ใ
์๋'๋ผ๊ณ ๋๋ตํจ",
|
| 108 |
+
"'๊ทผ๋ฐ ๊ทผ๋ฐ ์ฃผํด์๋น์ด ์ ๊ธํด๊ฐ๋ฅผ ์ค๋ค๋๋ง์ด์์ ๋ญ์ง ์ ์ดํด์๋ผ...' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ํ๋ฒ์ฐพ์๋ณผ๊ป์'๋ผ๊ณ ๋๋ตํจ",
|
| 109 |
+
"'์
ใ
ใ
' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ์ฌ๋ ์์ฌ๋ ์ฃผ๋น 15์๊ฐ ์ด์๊ทผ๋ฌดํ์ฌ๋์๋ฌด์กฐ๊ฑด ์ฃผํด์๋น์ ์ฃผ์ด์ผํ๋๋ดฅ์ด๊ฑฐ ์ฐธ๊ณ ํด๋ณผ๋์ฉ~?'๋ผ๊ณ ๋๋ตํจ",
|
| 110 |
+
"'๊ทผ๋ฐ 2์ฃผ๋ ์ฌ๋๋ ์ด์๋๋ฐ ๋ญ๊ฐ ์ด์ํด..ํ ' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ๊ณ์ ์ฃผ5์ผ์ด์ 15์๊ฐ์ด์๊ทผ๋ก์์๊ฒ๋ฌด์กฐ๊ฑด ์ง๊ธํ๋๊ฑด๊ฐ๋ด์๋๊ตฌ๋ ๊ทผ๋ก๊ณ์ฝ์ ์ ์ํ ๊ทผ๋ฌด๋ ์ง๋ง๊ธฐ, ์ด๊ทผ๋ก์๊ฐ / 4์ฃผ ํ๊ท 15์๊ฐ ์ด์ ๊ทผ๋ก ๊ฐ ์กฐ๊ฑด์ธ๊ฐ??'๋ผ๊ณ ๋๋ตํจ",
|
| 111 |
+
"'๊ทผ๋ฐ ํด๊ฐ ๋๋์ผ ํ์ฅ ์์ํ ๋ฏ ๊ทผ๋ฐ ํด๊ฐ ๋๋์ผ ํ์ฅ ์์ํ ๋ฏ ํด๊ฐ ๋ชป ๋ฐ๊ฟ. ์ง์ ๋ด๋ ค์์ผ 8์1์ผ~10์ผ ใ
' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ํ'๋ผ๊ณ ๋๋ตํจ",
|
| 112 |
+
"'1~9์ด๊ตฐ.' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ํํํด๊ฐ ๋ชป๋ฐ๊พธ๋ฉด ์ด์งธ??'๋ผ๊ณ ๋๋ตํจ",
|
| 113 |
+
"'์ด๋ฆ์ผ ๋ ๋ผ ์์ ผ๊ฑฐ ๋ชปํ๋ฏ!!! ์ด๋ฆ์ผ ๋ ๋ผ ์์ ผ๊ฑฐ ๋ชปํ๋ฏ!!! ์ด๋ฒ์ฃผ์ ๋ฉด์ ์ด ์ข์ข์ข์ ์๊ฒป์ด!!!!' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ํํค์๋ผ์จ'๋ผ๊ณ ๋๋ตํจ",
|
| 114 |
+
"'์
์
๋ฏธ์์ฐ!!!ใ
ใ
' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ใ
ใ
ใ
ใ
ใ
๊ด์ฐจ๋'๋ผ๊ณ ๋๋ตํจ",
|
| 115 |
+
"'์ค๋๋ ๋ฉด์ ๋ฐ์์จ' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ๊ณ ์ํ๋ค ใ
ใ
'๋ผ๊ณ ๋๋ตํจ",
|
| 116 |
+
"'์ ๊ท์ฌ!!!! ์ ๊ท์ฌ!!!! ์ ์ค๋ ์ฌ๋ฌด์ค ํผ์๊ฑฐ๋ก์ฌ!!!' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ์ค์คใ
๋๋ฐ์ต๊ณค๋ฐ???'๋ผ๊ณ ๋๋ตํจ",
|
| 117 |
+
"'๋
์์์ ์์ฃผ ํผ์ ํํฐํํฐํ ์ง๊ฒฝ์๋ค!!' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ๋ํํ
๋๋ฌ๊ฐ๊ณ ์ถ์์ฌ์ ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
๊ธํ๊ฑฐ ๋ง๊ณ ์ต๋ํ ์ผ ๋ด์ผ๋ก ๋ฏธ๋คํผ์์ผ๋ ์ผํ๋๊ฑฐ ์๋
ใ
'๋ผ๊ณ ๋๋ตํจ",
|
| 118 |
+
"'์ด์ ๋นจ๋ฆฌ์๊ณ ๋นจ๋ฆฌ์ผ๋ฌ๋๋ ์ฐ์ตํด์ผ์ผ... ์ด์ ๋นจ๋ฆฌ์๊ณ ๋นจ๋ฆฌ์ผ๋ฌ๋๋ ์ฐ์ตํด์ผ์ผ... 8์ ์ถ๊ทผ..ใ
ใ
' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ํ 8์์ถ๊ทผ!?ใ
ใ
ใ
ใ
๊ฒ๋ด ์ผ์ฐ์ถฉ๊ทผ์ด๋คใ
'๋ผ๊ณ ๋๋ตํจ",
|
| 119 |
+
"'์คํ 8์^^... ๊ทธ๋๋ ใ
ใ
๊ฐ์ 5์ ์ถ๊ทผ!!!ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
์คํ๋ถํฐ ๊ฐ๋ฅด์น ๊ฑด๊ฐ๋ฐ..' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ์ค์ค์น์คํํ๋ฉด ๋ช์์๋ง์ณ!?'๋ผ๊ณ ๋๋ตํจ",
|
| 120 |
+
"'์๊ธ์ด ๋ค์ด์์ด์ฌ ์๊ธ์ด ๋ค์ด์์ด์ฌ ์ด๋ฒ๋ฌ๋ถํฐ ์ญ๋ง๋์ด ์ฌ๋๋ค์ฌ..์กฐ๊ธ ์ฌ๋๋ค.ใ
ใ
,,, ์ธ๊ธ ๋น ์ง๋๊ฑด ๋๊ฐ์์ ๋คํ..' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ์ํ๋ค'๋ผ๊ณ ๋๋ตํจ",
|
| 121 |
+
"'์ญ์ด ๋ญ์ผ์ญ์ด ์ด๋ฐ ์ ์ฌ์๊ฐ์ ๋๋ณด๋ผ๊ฒก' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ์'๋ผ๊ณ ๋๋ตํจ",
|
| 122 |
+
"'์ผ์ ๋๋ฌด ์ผ์ฐ๋๋ด์ง๋ง๊ณ ์ผ์ ๋๋ฌด ์ผ์ฐ๋๋ด์ง๋ง๊ณ ์ฒ์ฒํํด๋ด์ใ
์ผ์ฐ ๋๋ด๋ฉด ์๊พธ ๋ค๋ฅธ์ผ์ด ๋ค์ด์..' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ์.. ๋ ๋นจ๋ฆฌ๋๋ด๋๊ณ ๋นจ๋ฆฌ ์ด๋ผ๊ณ ํ๋๊ฑด๋ฐ์ฌ๋ฉด ์๊พธ ์ผ์ด ๋ค์ด์ค๋๋ผใ
ใ
ใ
์๋ น์๊ฒ ํด์ผ๋๋๋ฐ ๋นจ๋ฆฌ๋นจ๋ฆฌ ์ฑ๊ฒฉ์ ์๋ผใ
'๋ผ๊ณ ๋๋ตํจ",
|
| 123 |
+
"'์ค๋น ๋ ๊ทธ๋ฐ์คํ์ผ์ธ๋ฐ ์ผ๊ฒ๋๋ง์ด์คใ
ใ
ใ
ใ
' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ์ฐ๋ฆฌ ์ ๋ง ํธ๊ตฌ์๋์ผ?ใ
ใ
ใ
ใ
์ผ์ ์ฐ๋ฆฌ๊ฐ ๋คํ๋์์ ์ฐจ์ฅ๋์ด..'๋ผ๊ณ ๋๋ตํจ",
|
| 124 |
+
"'๊ทธ๋ฌ๋ฉด 8์ ๋ง - 9์ ์ด์ ์ง์ ๊ฐ์ผํ๋ค๋๊ฑฐ์ ?? ๊ทธ๋ฌ๋ฉด 8์ ๋ง - 9์ ์ด์ ์ง์ ๊ฐ์ผํ๋ค๋๊ฑฐ์ ?? ์ฃค๋ ์ด ๋์งํธ ์๋์ ๋ฌด์จ ใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
กใ
ก ๋ต๋ค๋ฐ๊ฒ ์ผํ๋ค ์ฆ๋ง' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ๊ทธ๊ฑธ๋ชฐ๋ผ๊ทธ๋๊น๊ตญ๊ฐ์ง์ ๊ฐฑ ์ธํฐ๋ท๋ฑ๋ก์ธ๋ฐ์ด๋ฆ๊ฐ ์ ๋ฒ์ ์ง์ ๋ฑ๋ก์ด์๋์์๋ ์ ํํด์ ๋ฌผ์ด๋ณผ๊ฒ'๋ผ๊ณ ๋๋ตํจ",
|
| 125 |
+
"'ใ
ใ
ใทใ
' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ์๋์๋๋๊ธฐ๋คํํ
๋๋ฌผ์ด๋ดฃ๋'๋ผ๊ณ ๋๋ตํจ",
|
| 126 |
+
"'์์ฅ๋์ด ์์ฅ๋์ด ์ฌ๋ ค์ค ์ฒญ๋
์ฑ์ ๋ชป๋ฐ์๊ฑฐ๊ฐ์๋ฐ ์ค๋
๋ชป์ฑ์;;' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
'๋ผ๊ณ ๋๋ตํจ",
|
| 127 |
+
"'์ค๋ฌ์ง๋ด๊ฐ!์ฌ๊ธฐ๋ฃจ!' ๋ผ๊ณ '์ฒ ์'์๊ฒ ๋ฌผ์ด๋ดค์ ๋, '์ฒ ์'๋ ' ใ
ใ
ใ
ใ
ใ
์กฐ์'๋ผ๊ณ ๋๋ตํจ"]
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def submit(openai_api_key, question, image, *agents):
|
| 131 |
global CURRENT_POSITION
|
| 132 |
balloon = Image.open(os.path.join(os.path.dirname(__file__), 'data/balloon.png')).resize((64, 64))
|
| 133 |
new_image = Image.fromarray(image).convert('RGBA')
|
| 134 |
for k in range(TOTAL_K):
|
| 135 |
new_image.paste(balloon, [CURRENT_POSITION[k][0], CURRENT_POSITION[k][1] - 64], balloon)
|
| 136 |
|
| 137 |
+
# Answer
|
| 138 |
+
os.environ['OPENAI_API_KEY'] = openai_api_key
|
| 139 |
+
|
| 140 |
+
llm = ThinkGPT(model_name="gpt-3.5-turbo")
|
| 141 |
+
Answer = llm.predict(question, remember=llm.remember('์ฒ ์', limit = 30))
|
| 142 |
+
|
| 143 |
new_agents = []
|
| 144 |
for k in range(TOTAL_K):
|
| 145 |
new_agents.append(Answer)
|
|
|
|
| 147 |
return np.array(new_image), *[gr.Textbox.update(value=answer) for answer in new_agents]
|
| 148 |
|
| 149 |
theme = gr.themes.Default(primary_hue="green")
|
| 150 |
+
|
| 151 |
agents = []
|
| 152 |
with gr.Blocks(css = """#col_container { margin-left: auto; margin-right: auto;}
|
| 153 |
#chatbot {height: 520px; overflow: auto;}""",
|
|
|
|
| 158 |
#gr.HTML('''<center><a href="https://huggingface.co/spaces/yuntian-deng/ChatGPT?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>Duplicate the Space and run securely with your OpenAI API Key</center>''')
|
| 159 |
with gr.Column(elem_id = "col_container", visible=False) as main_block:
|
| 160 |
|
| 161 |
+
|
| 162 |
with gr.Row():
|
| 163 |
with gr.Column(scale=7):
|
| 164 |
image = gr.Image(os.path.join(os.path.dirname(__file__), "data/Court.jpeg"), height = 800, width = 1600)
|
|
|
|
| 167 |
text = gr.Textbox(label=f"Random Sample - {idx+1}")
|
| 168 |
agents.append(text)
|
| 169 |
|
|
|
|
| 170 |
with gr.Row():
|
| 171 |
+
with gr.Column(scale=3):
|
| 172 |
+
openai_api_key = gr.Textbox(placeholder= "sk-", label= "Type an openai api key")
|
| 173 |
+
|
| 174 |
+
with gr.Column(scale=4):
|
| 175 |
+
question = gr.Textbox(placeholder= "Hi there!", label= "Type an input and press Enter") #t
|
| 176 |
+
|
| 177 |
with gr.Column(scale=3):
|
| 178 |
b1 = gr.Button('Submit', visible=not DISABLED)
|
| 179 |
|
|
|
|
| 218 |
accept_checkbox.change(fn=enable_inputs, inputs=[], outputs=[user_consent_block, main_block], queue=False)
|
| 219 |
|
| 220 |
b0.click(random_sample, inputs = [], outputs = [image])
|
| 221 |
+
b2.click(reset_sample, inputs = [], outputs = [image])
|
| 222 |
|
| 223 |
+
b1.click(submit, inputs = [openai_api_key, question, image, *agents], outputs = [image, *agents])
|
| 224 |
|
| 225 |
# inputs.submit(reset_textbox, [], [inputs, b1], queue=False)
|
| 226 |
# inputs.submit(predict, [inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter, server_status_code, inputs, b1],) #openai_api_key
|