Commit
·
b276b4d
1
Parent(s):
995d107
add deepseek-r1
Browse files
app.py
CHANGED
@@ -6,6 +6,11 @@ from typing import Dict, List, Optional, Tuple
|
|
6 |
|
7 |
import gradio as gr
|
8 |
from loguru import logger
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
import sambanova_gradio
|
11 |
from sambanova_gradio import get_fn
|
@@ -311,6 +316,23 @@ with gr.Blocks(css_paths="app.css", title="Qwen2.5 Coder Artifacts (+SambaNova+F
|
|
311 |
|
312 |
input = antd.InputTextarea(size="middle", allow_clear=True, placeholder="Please enter what kind of application you want")
|
313 |
code_language = gr.Textbox(label="code language", lines=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
btn = antd.Button("send", type="primary", size="large")
|
315 |
|
316 |
with antd.Flex(gap="small", wrap=True):
|
@@ -359,10 +381,10 @@ with gr.Blocks(css_paths="app.css", title="Qwen2.5 Coder Artifacts (+SambaNova+F
|
|
359 |
sandbox = gr.HTML(elem_classes="html_content")
|
360 |
with antd.Tabs.Item(key="render_other", label="Render_Code") as render_other:
|
361 |
sandbox_other = legacy.Markdown()
|
362 |
-
|
363 |
-
|
364 |
|
365 |
-
def generation_code(query: Optional[str], code_language, _setting: Dict[str, str], _history: Optional[History]):
|
366 |
if query is None:
|
367 |
query = ''
|
368 |
if _history is None:
|
@@ -387,7 +409,7 @@ with gr.Blocks(css_paths="app.css", title="Qwen2.5 Coder Artifacts (+SambaNova+F
|
|
387 |
|
388 |
# Get the model from sambanova_gradio
|
389 |
fn = get_fn(
|
390 |
-
model_name=
|
391 |
preprocess=preprocess,
|
392 |
postprocess=postprocess,
|
393 |
api_key=YOUR_API_TOKEN
|
@@ -407,6 +429,14 @@ with gr.Blocks(css_paths="app.css", title="Qwen2.5 Coder Artifacts (+SambaNova+F
|
|
407 |
}
|
408 |
|
409 |
assistant_response = response_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
410 |
local_history.append([query, assistant_response])
|
411 |
|
412 |
code = remove_code_block(assistant_response, language=code_language)
|
@@ -435,6 +465,8 @@ with gr.Blocks(css_paths="app.css", title="Qwen2.5 Coder Artifacts (+SambaNova+F
|
|
435 |
render_other: render_other_val,
|
436 |
sandbox_other: sandbox_other_val,
|
437 |
code_syntax_check: code_syntax_check_val,
|
|
|
|
|
438 |
}
|
439 |
|
440 |
def code_language_example_change(code_language):
|
@@ -453,9 +485,9 @@ with gr.Blocks(css_paths="app.css", title="Qwen2.5 Coder Artifacts (+SambaNova+F
|
|
453 |
)
|
454 |
|
455 |
btn.click(generation_code,
|
456 |
-
inputs=[input, code_language, setting, history_state],
|
457 |
outputs=[code_output, history_state, sandbox, state_tab, code_drawer,
|
458 |
-
render_html, render_other, sandbox_other, code_syntax_check])
|
459 |
|
460 |
clear_btn.click(clear_history, inputs=[], outputs=[history_state])
|
461 |
|
|
|
6 |
|
7 |
import gradio as gr
|
8 |
from loguru import logger
|
9 |
+
try:
|
10 |
+
from utils import init_logger
|
11 |
+
logger = init_logger()
|
12 |
+
except Exception as e:
|
13 |
+
logger.info(f"import_error: {str(e)}")
|
14 |
|
15 |
import sambanova_gradio
|
16 |
from sambanova_gradio import get_fn
|
|
|
316 |
|
317 |
input = antd.InputTextarea(size="middle", allow_clear=True, placeholder="Please enter what kind of application you want")
|
318 |
code_language = gr.Textbox(label="code language", lines=1)
|
319 |
+
LLM_model = gr.Dropdown(
|
320 |
+
choices=[
|
321 |
+
"Qwen2.5-Coder-32B-Instruct",
|
322 |
+
"DeepSeek-R1-Distill-Llama-70B",
|
323 |
+
"Llama-3.1-Tulu-3-405B",
|
324 |
+
"Meta-Llama-3.3-70B-Instruct",
|
325 |
+
"Meta-Llama-3.2-3B-Instruct",
|
326 |
+
"Meta-Llama-3.2-1B-Instruct",
|
327 |
+
"Meta-Llama-3.1-70B-Instruct",
|
328 |
+
"Meta-Llama-3.1-405B-Instruct",
|
329 |
+
"Meta-Llama-3.1-8B-Instruct",
|
330 |
+
"QwQ-32B-Preview",
|
331 |
+
"Qwen2.5-72B-Instruct",
|
332 |
+
],
|
333 |
+
label="LLM model",
|
334 |
+
value="Qwen2.5-Coder-32B-Instruct",
|
335 |
+
)
|
336 |
btn = antd.Button("send", type="primary", size="large")
|
337 |
|
338 |
with antd.Flex(gap="small", wrap=True):
|
|
|
381 |
sandbox = gr.HTML(elem_classes="html_content")
|
382 |
with antd.Tabs.Item(key="render_other", label="Render_Code") as render_other:
|
383 |
sandbox_other = legacy.Markdown()
|
384 |
+
code_syntax_check = gr.Textbox(label="check code syntax: ", lines=1, interactive=False)
|
385 |
+
think_content = gr.Textbox(label="think_content: ", lines=10, interactive=False, visible=False)
|
386 |
|
387 |
+
def generation_code(query: Optional[str], code_language, _setting: Dict[str, str], _history: Optional[History], LLM_model):
|
388 |
if query is None:
|
389 |
query = ''
|
390 |
if _history is None:
|
|
|
409 |
|
410 |
# Get the model from sambanova_gradio
|
411 |
fn = get_fn(
|
412 |
+
model_name=LLM_model,
|
413 |
preprocess=preprocess,
|
414 |
postprocess=postprocess,
|
415 |
api_key=YOUR_API_TOKEN
|
|
|
429 |
}
|
430 |
|
431 |
assistant_response = response_text
|
432 |
+
pattern = r'<think>\n(.*?)</think>\n'
|
433 |
+
match = re.search(pattern, assistant_response, flags=re.DOTALL)
|
434 |
+
if match:
|
435 |
+
think_content_val = match.group(1)
|
436 |
+
else:
|
437 |
+
think_content_val = ""
|
438 |
+
assistant_response = re.sub(pattern, '', assistant_response, flags=re.DOTALL)
|
439 |
+
|
440 |
local_history.append([query, assistant_response])
|
441 |
|
442 |
code = remove_code_block(assistant_response, language=code_language)
|
|
|
465 |
render_other: render_other_val,
|
466 |
sandbox_other: sandbox_other_val,
|
467 |
code_syntax_check: code_syntax_check_val,
|
468 |
+
think_content: think_content_val,
|
469 |
+
think_content: gr.update(visible=(think_content_val!="")),
|
470 |
}
|
471 |
|
472 |
def code_language_example_change(code_language):
|
|
|
485 |
)
|
486 |
|
487 |
btn.click(generation_code,
|
488 |
+
inputs=[input, code_language, setting, history_state, LLM_model],
|
489 |
outputs=[code_output, history_state, sandbox, state_tab, code_drawer,
|
490 |
+
render_html, render_other, sandbox_other, code_syntax_check, think_content, think_content])
|
491 |
|
492 |
clear_btn.click(clear_history, inputs=[], outputs=[history_state])
|
493 |
|