Delete app-backup.py
Browse files- app-backup.py +0 -177
app-backup.py
DELETED
|
@@ -1,177 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import os
|
| 3 |
-
import requests
|
| 4 |
-
import json
|
| 5 |
-
|
| 6 |
-
def create_deepseek_interface():
|
| 7 |
-
# ์ฑํ
๊ธฐ๋ก ์ํ๋ฅผ ์ ์ฅํ State ๊ฐ์ฒด
|
| 8 |
-
def query_deepseek(message, history, api_key):
|
| 9 |
-
if not api_key:
|
| 10 |
-
return history, "Fireworks AI API ํค๋ฅผ ์
๋ ฅํด์ฃผ์ธ์"
|
| 11 |
-
|
| 12 |
-
# API ์์ฒญ์ ์ํ ๋ํ ๊ธฐ๋ก ์ค๋น
|
| 13 |
-
messages = []
|
| 14 |
-
for user, assistant in history:
|
| 15 |
-
messages.append({"role": "user", "content": user})
|
| 16 |
-
messages.append({"role": "assistant", "content": assistant})
|
| 17 |
-
|
| 18 |
-
# ์ ์ฌ์ฉ์ ๋ฉ์์ง ์ถ๊ฐ
|
| 19 |
-
messages.append({"role": "user", "content": message})
|
| 20 |
-
|
| 21 |
-
# API ์์ฒญ ์ค๋น
|
| 22 |
-
url = "https://api.fireworks.ai/inference/v1/chat/completions"
|
| 23 |
-
payload = {
|
| 24 |
-
"model": "accounts/fireworks/models/deepseek-v3-0324",
|
| 25 |
-
"max_tokens": 20480,
|
| 26 |
-
"top_p": 1,
|
| 27 |
-
"top_k": 40,
|
| 28 |
-
"presence_penalty": 0,
|
| 29 |
-
"frequency_penalty": 0,
|
| 30 |
-
"temperature": 0.6,
|
| 31 |
-
"messages": messages
|
| 32 |
-
}
|
| 33 |
-
headers = {
|
| 34 |
-
"Accept": "application/json",
|
| 35 |
-
"Content-Type": "application/json",
|
| 36 |
-
"Authorization": f"Bearer {api_key}"
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
try:
|
| 40 |
-
# API ์์ฒญ ์ ์ก
|
| 41 |
-
response = requests.request("POST", url, headers=headers, data=json.dumps(payload))
|
| 42 |
-
response.raise_for_status() # HTTP ์ค๋ฅ ๋ฐ์ ์ ์์ธ ๋ฐ์
|
| 43 |
-
|
| 44 |
-
# ์๋ต ์ถ์ถ
|
| 45 |
-
result = response.json()
|
| 46 |
-
assistant_response = result.get("choices", [{}])[0].get("message", {}).get("content", "")
|
| 47 |
-
|
| 48 |
-
# ๋ํ ๊ธฐ๋ก ์
๋ฐ์ดํธ (Gradio chatbot ํ์์ผ๋ก)
|
| 49 |
-
history.append((message, assistant_response))
|
| 50 |
-
return history, ""
|
| 51 |
-
except requests.exceptions.RequestException as e:
|
| 52 |
-
error_msg = f"API ์ค๋ฅ: {str(e)}"
|
| 53 |
-
if hasattr(e, 'response') and e.response and e.response.status_code == 401:
|
| 54 |
-
error_msg = "์ธ์ฆ ์คํจ. API ํค๋ฅผ ํ์ธํด์ฃผ์ธ์."
|
| 55 |
-
return history, error_msg
|
| 56 |
-
|
| 57 |
-
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
| 58 |
-
with gr.Blocks(theme="soft", fill_height=True) as demo:
|
| 59 |
-
# ํค๋ ์น์
|
| 60 |
-
gr.Markdown(
|
| 61 |
-
"""
|
| 62 |
-
# ๐ค DeepSeek V3 ์ถ๋ก ์ธํฐํ์ด์ค
|
| 63 |
-
### Fireworks AI๊ฐ ์ ๊ณตํ๋ ๊ณ ๊ธ AI ๋ชจ๋ธ
|
| 64 |
-
"""
|
| 65 |
-
)
|
| 66 |
-
|
| 67 |
-
# ๋ฉ์ธ ๋ ์ด์์ (๋ ๊ฐ์ ์ด)
|
| 68 |
-
with gr.Row():
|
| 69 |
-
# ์ฌ์ด๋๋ฐ - ๋ชจ๋ธ ์ ๋ณด ๋ฐ API ํค
|
| 70 |
-
with gr.Column(scale=1):
|
| 71 |
-
gr.Markdown(
|
| 72 |
-
"""
|
| 73 |
-
## ๐ ์ ๊ทผ ์ ์ด
|
| 74 |
-
### ์ถ๋ก ์ ๊ณต์
|
| 75 |
-
์ด ์ธํฐํ์ด์ค๋ Fireworks AI API๋ฅผ ํตํด ์ ๊ณต๋๋ DeepSeek-V3 ๋ชจ๋ธ์ ์ฐ๊ฒฐ๋ฉ๋๋ค.
|
| 76 |
-
|
| 77 |
-
#### ์ธ์ฆ
|
| 78 |
-
- ์๋์ Fireworks AI API ํค๋ฅผ ์
๋ ฅํ์ธ์
|
| 79 |
-
- ์๋-ํฌ-์๋ ์ํธํ๋ก ์์ ํ API ์ ๊ทผ
|
| 80 |
-
"""
|
| 81 |
-
)
|
| 82 |
-
|
| 83 |
-
# API ํค ์
๋ ฅ
|
| 84 |
-
api_key = gr.Textbox(
|
| 85 |
-
label="Fireworks AI API ํค",
|
| 86 |
-
placeholder="API ํค๋ฅผ ์
๋ ฅํ์ธ์...",
|
| 87 |
-
type="password"
|
| 88 |
-
)
|
| 89 |
-
|
| 90 |
-
# ๋ชจ๋ธ ์ธ๋ถ ์ ๋ณด ์น์
|
| 91 |
-
gr.Markdown(
|
| 92 |
-
"""
|
| 93 |
-
### ๐ ๋ชจ๋ธ ์ธ๋ถ ์ ๋ณด
|
| 94 |
-
- **๋ชจ๋ธ**: DeepSeek-V3-0324
|
| 95 |
-
- **์ ๊ณต์**: Fireworks AI
|
| 96 |
-
- **์ต๋ ํ ํฐ**: 20,480
|
| 97 |
-
- **์จ๋**: 0.6
|
| 98 |
-
- **๊ธฐ๋ฅ**: ๊ณ ๊ธ ์ธ์ด ์ดํด
|
| 99 |
-
"""
|
| 100 |
-
)
|
| 101 |
-
|
| 102 |
-
# ์ค๋ฅ ๋ฉ์์ง ํ์
|
| 103 |
-
error_box = gr.Markdown("")
|
| 104 |
-
|
| 105 |
-
# ๋ฉ์ธ ์ฝํ
์ธ ์์ญ
|
| 106 |
-
with gr.Column(scale=2):
|
| 107 |
-
# ์ฑํ
์ธํฐํ์ด์ค
|
| 108 |
-
chatbot = gr.Chatbot(
|
| 109 |
-
height=500,
|
| 110 |
-
show_label=False,
|
| 111 |
-
container=True
|
| 112 |
-
)
|
| 113 |
-
|
| 114 |
-
# ์
๋ ฅ ์์ญ
|
| 115 |
-
with gr.Row():
|
| 116 |
-
msg = gr.Textbox(
|
| 117 |
-
label="๋ฉ์์ง",
|
| 118 |
-
placeholder="์ฌ๊ธฐ์ ํ๋กฌํํธ๋ฅผ ์
๋ ฅํ์ธ์...",
|
| 119 |
-
show_label=False,
|
| 120 |
-
scale=9
|
| 121 |
-
)
|
| 122 |
-
submit = gr.Button("์ ์ก", variant="primary", scale=1)
|
| 123 |
-
|
| 124 |
-
# ๋ํ ์ด๊ธฐํ ๋ฒํผ
|
| 125 |
-
with gr.Row():
|
| 126 |
-
clear = gr.ClearButton([msg, chatbot], value="๐งน ๋ํ ์ด๊ธฐํ")
|
| 127 |
-
|
| 128 |
-
# ์์ ์ฟผ๋ฆฌ
|
| 129 |
-
gr.Examples(
|
| 130 |
-
examples=[
|
| 131 |
-
"๋ฅ๋ฌ๋์๏ฟฝ๏ฟฝ ํธ๋์คํฌ๋จธ์ RNN์ ์ฐจ์ด์ ์ ์ค๋ช
ํด์ฃผ์ธ์.",
|
| 132 |
-
"ํน์ ๋ฒ์ ๋ด์ ์์๋ฅผ ์ฐพ๋ ํ์ด์ฌ ํจ์๋ฅผ ์์ฑํด์ฃผ์ธ์.",
|
| 133 |
-
"๊ฐํํ์ต์ ์ฃผ์ ๊ฐ๋
์ ์์ฝํด์ฃผ์ธ์."
|
| 134 |
-
],
|
| 135 |
-
inputs=msg
|
| 136 |
-
)
|
| 137 |
-
|
| 138 |
-
# ํผ ์ ์ถ ์ฒ๋ฆฌ
|
| 139 |
-
def process_query(message, history, api_key):
|
| 140 |
-
if not message.strip():
|
| 141 |
-
return history, ""
|
| 142 |
-
|
| 143 |
-
updated_history, error = query_deepseek(message, history, api_key)
|
| 144 |
-
|
| 145 |
-
if error:
|
| 146 |
-
return history, f"**์ค๋ฅ:** {error}"
|
| 147 |
-
else:
|
| 148 |
-
return updated_history, ""
|
| 149 |
-
|
| 150 |
-
# ๋ฒํผ๊ณผ ๊ธฐ๋ฅ ์ฐ๊ฒฐ
|
| 151 |
-
submit.click(
|
| 152 |
-
process_query,
|
| 153 |
-
inputs=[msg, chatbot, api_key],
|
| 154 |
-
outputs=[chatbot, error_box]
|
| 155 |
-
).then(
|
| 156 |
-
lambda: "",
|
| 157 |
-
None,
|
| 158 |
-
[msg]
|
| 159 |
-
)
|
| 160 |
-
|
| 161 |
-
# Enter ํค ์ ์ถ ํ์ฉ
|
| 162 |
-
msg.submit(
|
| 163 |
-
process_query,
|
| 164 |
-
inputs=[msg, chatbot, api_key],
|
| 165 |
-
outputs=[chatbot, error_box]
|
| 166 |
-
).then(
|
| 167 |
-
lambda: "",
|
| 168 |
-
None,
|
| 169 |
-
[msg]
|
| 170 |
-
)
|
| 171 |
-
|
| 172 |
-
return demo
|
| 173 |
-
|
| 174 |
-
# ์ธํฐํ์ด์ค ์คํ
|
| 175 |
-
if __name__ == "__main__":
|
| 176 |
-
demo = create_deepseek_interface()
|
| 177 |
-
demo.launch(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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