Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
|
|
|
|
164 |
messages = [{"role": "system", "content": system_message}]
|
165 |
for chat in chat_history:
|
166 |
-
messages.append({"role": "user", "content": chat["
|
167 |
-
messages.append({"role": "assistant", "content": chat["
|
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: #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
}
|
197 |
.tab-nav button.selected {
|
198 |
-
color: #
|
199 |
-
|
|
|
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="
|
253 |
msg = gr.Textbox(label="λ©μμ§")
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
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,
|
272 |
-
bot_message = respond(message, chat_history,
|
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,
|
|
|
|
|
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()
|