arxivgpt kim commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,80 +1,16 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
import sys
|
| 4 |
-
import json
|
| 5 |
-
import requests
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
# ๋ํ ์ด๋ ฅ์ ์ ์ฅํ ๊ธ๋ก๋ฒ ๋ณ์
|
| 14 |
-
conversation_history = []
|
| 15 |
-
|
| 16 |
-
def exception_handler(exception_type, exception, traceback):
|
| 17 |
-
print(f"{exception_type.__name__}: {exception}")
|
| 18 |
-
|
| 19 |
-
sys.excepthook = exception_handler
|
| 20 |
-
sys.tracebacklimit = 0
|
| 21 |
-
|
| 22 |
-
def predict(inputs):
|
| 23 |
-
global conversation_history
|
| 24 |
-
conversation_history.append({"role": "user", "content": inputs})
|
| 25 |
-
|
| 26 |
-
payload = {
|
| 27 |
-
"model": "gpt-4-0125-preview",
|
| 28 |
-
"messages": conversation_history
|
| 29 |
-
}
|
| 30 |
-
|
| 31 |
-
headers = {
|
| 32 |
-
"Content-Type": "application/json",
|
| 33 |
-
"Authorization": f"Bearer {OPENAI_API_KEY}"
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
| 37 |
-
if response.status_code == 200:
|
| 38 |
-
data = response.json()
|
| 39 |
-
response_text = data['choices'][0]['message']['content']
|
| 40 |
-
# ๋ํ ์ด๋ ฅ์ AI ์๋ต ์ถ๊ฐ
|
| 41 |
-
conversation_history.append({"role": "assistant", "content": response_text})
|
| 42 |
-
response_html = response_text.replace('\n', '<br>')
|
| 43 |
-
return f"<div style='max-height: 400px; overflow-y: auto;'>{response_html}</div>"
|
| 44 |
-
else:
|
| 45 |
-
return f"<div style='color: red;'>์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ์ํ ์ฝ๋: {response.status_code}</div>"
|
| 46 |
-
|
| 47 |
-
# CSS ๋ฐ Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ์ ๋์ผํ๊ฒ ์ ์ง
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
css = """
|
| 53 |
-
footer {
|
| 54 |
-
visibility: hidden;
|
| 55 |
-
}
|
| 56 |
-
"""
|
| 57 |
-
|
| 58 |
-
# gr.Blocks๋ฅผ ์ฌ์ฉํ์ฌ ๋ ์ด์์์ ๊ตฌ์ฑํฉ๋๋ค.
|
| 59 |
-
with gr.Blocks(css=css) as demo:
|
| 60 |
-
gr.Markdown("# AIQ Codepilot", elem_id="markdown-title")
|
| 61 |
-
gr.Markdown("## AI ์๋น์ค ์๋ ์์ฑ AI ์๋น์ค: ๋ง๋ค๊ณ ์ถ์ ์๋น์ค์ ๋ด์ฉ๋ง ์
๋ ฅํ๋ฉด AI๊ฐ ์๋์ผ๋ก ์ฝ๋ฉํ๊ณ ์ฌ์ดํธ ๊ณต๊ฐ๋ฅผ ์ง์ํฉ๋๋ค.", elem_id="markdown-description")
|
| 62 |
-
gr.Markdown("### ์์ 1: ํ
์คํธ๋ฅผ ์
๋ ฅํ๋ฉด ์์ฑ์์ฑ('gtts') ์๋น์ค ์์ฑ", elem_id="markdown-description")
|
| 63 |
-
gr.Markdown("### ์์ 2: MBTI 20๋ฌธํญ์ ์์ฑํ๊ณ ์๋ตํ๋ฉด 16๊ฐ ์ ํ ์๋ ๊ฒ์ฌ ์๋น์ค ์์ฑ ", elem_id="markdown-description")
|
| 64 |
-
|
| 65 |
-
with gr.Row():
|
| 66 |
-
text_input = gr.Textbox(label="๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์...", placeholder="์ฌ๊ธฐ์ ์
๋ ฅํ์ธ์...")
|
| 67 |
-
with gr.Row():
|
| 68 |
-
submit_button = gr.Button("์ ์ก")
|
| 69 |
-
output_html = gr.HTML(label="AI ์๋ต")
|
| 70 |
-
|
| 71 |
-
submit_button.click(
|
| 72 |
-
fn=predict,
|
| 73 |
-
inputs=text_input,
|
| 74 |
-
outputs=output_html
|
| 75 |
-
)
|
| 76 |
-
|
| 77 |
-
# ์ธํฐํ์ด์ค ์คํ
|
| 78 |
-
demo.launch(auth=("arxiv", "gpt"))
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
def generate_image(text):
|
| 5 |
+
dalle_mini = pipeline(โtext-to-image-generationโ, model=โCompVis/ldm-dalle-miniโ)
|
| 6 |
+
images = dalle_mini(text)
|
| 7 |
+
return images[0][โurlโ]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
iface = gr.Interface(fn=generate_image,
|
| 10 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder=โ์ฌ๊ธฐ์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ ํ
์คํธ๋ฅผ ์
๋ ฅํ์ธ์โ),
|
| 11 |
+
outputs=โimageโ,
|
| 12 |
+
title=โDALLยทE Mini๋ฅผ ์ด์ฉํ ์ด๋ฏธ์ง ์์ฑโ,
|
| 13 |
+
description=โํ
์คํธ๋ฅผ ์
๋ ฅํ๋ฉด, ์
๋ ฅ๋ ํ
์คํธ์ ๊ธฐ๋ฐํ ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค.โ)
|
| 14 |
|
| 15 |
+
if name == โmainโ:
|
| 16 |
+
iface.launch()
|