arxivgpt kim commited on
Commit
9f57d6c
ยท
verified ยท
1 Parent(s): 698d2c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -76
app.py CHANGED
@@ -1,80 +1,16 @@
1
  import gradio as gr
2
- import os
3
- import sys
4
- import json
5
- import requests
6
 
7
- # ํ™˜๊ฒฝ ๋ณ€์ˆ˜์—์„œ ํ•„์š”ํ•œ ์„ค์ •์„ ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.
8
- API_URL = os.getenv("API_URL")
9
- OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") # ํ™˜๊ฒฝ๋ณ€์ˆ˜์—์„œ API ํ‚ค๋ฅผ ๋กœ๋“œํ•˜๋„๋ก ๋ณ€๊ฒฝ
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()