ginipick commited on
Commit
c292539
Β·
verified Β·
1 Parent(s): 0370aef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -18
app.py CHANGED
@@ -158,15 +158,17 @@ def analyze_space(url: str, progress=gr.Progress()):
158
  return f"였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}", "", None, "", "", "", ""
159
 
160
 
161
-
162
-
163
- def respond(message: str, chat_history: List[Dict[str, str]], system_message: str, max_tokens: int, temperature: float, top_p: float):
 
 
164
  messages = [{"role": "system", "content": system_message}]
165
  for chat in chat_history:
166
- messages.append({"role": "user", "content": chat["role"] == "user"})
167
- messages.append({"role": "assistant", "content": chat["role"] == "assistant"})
168
  messages.append({"role": "user", "content": message})
169
-
170
  try:
171
  response = hf_client.chat_completion(messages, max_tokens=max_tokens, temperature=temperature, top_p=top_p)
172
  return response.choices[0].message.content
@@ -191,12 +193,26 @@ def create_ui():
191
  height: calc(100vh - 200px) !important;
192
  overflow-y: auto !important;
193
  }
 
 
 
 
 
194
  .tab-nav button {
195
- color: #7FFFD4 !important; /* ν˜•κ΄‘ 민트 색상 */
 
 
 
 
 
 
 
 
196
  }
197
  .tab-nav button.selected {
198
- color: #FFFF00 !important; /* 밝은 ν˜•κ΄‘ 옐둜우 */
199
- border-color: #FFFF00 !important;
 
200
  }
201
  .file-button {
202
  background-color: #f0f0f0;
@@ -210,8 +226,13 @@ def create_ui():
210
  .file-button:hover {
211
  background-color: #e0e0e0;
212
  }
 
 
 
 
213
  """
214
 
 
215
  with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
216
  gr.Markdown("# HuggingFace Space Analyzer")
217
 
@@ -248,14 +269,15 @@ def create_ui():
248
  with requirements_tab:
249
  requirements_content = gr.Textbox(label="requirements.txt", lines=30)
250
 
 
251
  with gr.TabItem("AI μ½”λ”©"):
252
- chatbot = gr.Chatbot(label="λŒ€ν™”", type="messages")
253
  msg = gr.Textbox(label="λ©”μ‹œμ§€")
254
- with gr.Row():
255
- system_message = gr.Textbox(label="System Message", value="")
256
- max_tokens = gr.Slider(minimum=1, maximum=8000, value=4000, label="Max Tokens")
257
- temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature")
258
- top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
259
 
260
  examples = [
261
  ["μƒμ„Έν•œ μ‚¬μš© 방법을 마치 화면을 λ³΄λ©΄μ„œ μ„€λͺ…ν•˜λ“―이 4000 토큰 이상 μžμ„Ένžˆ μ„€λͺ…ν•˜λΌ"],
@@ -268,13 +290,15 @@ def create_ui():
268
 
269
  gr.Examples(examples, inputs=msg)
270
 
271
- def respond_wrapper(message, chat_history, system_message, max_tokens, temperature, top_p):
272
- bot_message = respond(message, chat_history, system_message, max_tokens, temperature, top_p)
273
  chat_history.append({"role": "user", "content": message})
274
  chat_history.append({"role": "assistant", "content": bot_message})
275
  return "", chat_history
276
 
277
- msg.submit(respond_wrapper, [msg, chatbot, system_message, max_tokens, temperature, top_p], [msg, chatbot])
 
 
278
 
279
  space_id_state = gr.State()
280
  tree_structure_state = gr.State()
 
158
  return f"였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}", "", None, "", "", "", ""
159
 
160
 
161
+ def respond(message: str, chat_history: List[Dict[str, str]], max_tokens: int, temperature: float, top_p: float) -> str:
162
+ system_message = """당신은 ν—ˆκΉ…νŽ˜μ΄μŠ€μ— νŠΉν™”λœ AI μ½”λ”© μ „λ¬Έκ°€μž…λ‹ˆλ‹€. μ‚¬μš©μžμ˜ μ§ˆλ¬Έμ— μΉœμ ˆν•˜κ³  μƒμ„Έν•˜κ²Œ λ‹΅λ³€ν•΄μ£Όμ„Έμš”.
163
+ Gradio νŠΉμ„±μ„ μ •ν™•νžˆ μΈμ‹ν•˜κ³  Requirements.txt λˆ„λ½μ—†μ΄ μ½”λ”©κ³Ό 였λ₯˜λ₯Ό ν•΄κ²°ν•΄μ•Ό ν•©λ‹ˆλ‹€.
164
+ 항상 μ •ν™•ν•˜κ³  μœ μš©ν•œ 정보λ₯Ό μ œκ³΅ν•˜λ„λ‘ λ…Έλ ₯ν•˜μ„Έμš”."""
165
+
166
  messages = [{"role": "system", "content": system_message}]
167
  for chat in chat_history:
168
+ messages.append({"role": "user", "content": chat["content"]})
169
+ messages.append({"role": "assistant", "content": chat["content"]})
170
  messages.append({"role": "user", "content": message})
171
+
172
  try:
173
  response = hf_client.chat_completion(messages, max_tokens=max_tokens, temperature=temperature, top_p=top_p)
174
  return response.choices[0].message.content
 
193
  height: calc(100vh - 200px) !important;
194
  overflow-y: auto !important;
195
  }
196
+ .tab-nav {
197
+ background-color: #2c3e50;
198
+ border-radius: 5px 5px 0 0;
199
+ overflow: hidden;
200
+ }
201
  .tab-nav button {
202
+ color: #ecf0f1 !important;
203
+ background-color: #34495e;
204
+ border: none;
205
+ padding: 10px 20px;
206
+ margin: 0;
207
+ transition: background-color 0.3s;
208
+ }
209
+ .tab-nav button:hover {
210
+ background-color: #2980b9;
211
  }
212
  .tab-nav button.selected {
213
+ color: #2c3e50 !important;
214
+ background-color: #ecf0f1;
215
+ font-weight: bold;
216
  }
217
  .file-button {
218
  background-color: #f0f0f0;
 
226
  .file-button:hover {
227
  background-color: #e0e0e0;
228
  }
229
+ input[type="text"], textarea {
230
+ color: #2c3e50 !important;
231
+ background-color: #ecf0f1 !important;
232
+ }
233
  """
234
 
235
+
236
  with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
237
  gr.Markdown("# HuggingFace Space Analyzer")
238
 
 
269
  with requirements_tab:
270
  requirements_content = gr.Textbox(label="requirements.txt", lines=30)
271
 
272
+
273
  with gr.TabItem("AI μ½”λ”©"):
274
+ chatbot = gr.Chatbot(label="λŒ€ν™”", type="message")
275
  msg = gr.Textbox(label="λ©”μ‹œμ§€")
276
+
277
+ # μˆ¨κ²¨μ§„ μƒνƒœλ‘œ νŒŒλΌλ―Έν„° μ„€μ •
278
+ max_tokens = gr.Slider(minimum=1, maximum=8000, value=4000, label="Max Tokens", visible=False)
279
+ temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature", visible=False)
280
+ top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P", visible=False)
281
 
282
  examples = [
283
  ["μƒμ„Έν•œ μ‚¬μš© 방법을 마치 화면을 λ³΄λ©΄μ„œ μ„€λͺ…ν•˜λ“―이 4000 토큰 이상 μžμ„Ένžˆ μ„€λͺ…ν•˜λΌ"],
 
290
 
291
  gr.Examples(examples, inputs=msg)
292
 
293
+ def respond_wrapper(message, chat_history, max_tokens, temperature, top_p):
294
+ bot_message = respond(message, chat_history, max_tokens, temperature, top_p)
295
  chat_history.append({"role": "user", "content": message})
296
  chat_history.append({"role": "assistant", "content": bot_message})
297
  return "", chat_history
298
 
299
+ msg.submit(respond_wrapper, [msg, chatbot, max_tokens, temperature, top_p], [msg, chatbot])
300
+
301
+
302
 
303
  space_id_state = gr.State()
304
  tree_structure_state = gr.State()