openfree commited on
Commit
0e99b95
ยท
verified ยท
1 Parent(s): 81be010

Delete app-backup.py

Browse files
Files changed (1) hide show
  1. 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)