Spaces:
Runtime error
Runtime error
File size: 4,699 Bytes
182c7c5 c00e791 182c7c5 c00e791 182c7c5 c00e791 182c7c5 c00e791 182c7c5 c00e791 182c7c5 c00e791 182c7c5 c00e791 182c7c5 c00e791 182c7c5 c00e791 182c7c5 c00e791 182c7c5 c00e791 182c7c5 c00e791 182c7c5 c00e791 182c7c5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
import gradio as gr
from ctransformers import AutoModelForCausalLM
model_name = "lmstudio-community/Devstral-Small-2505-GGUF"
model_file = "devstral-small-2505.Q4_K_M.gguf" # Выберем версию с квантизацией Q4_K_M для экономии памяти
model = AutoModelForCausalLM.from_pretrained(
model_name,
model_file=model_file,
model_type="mistral",
gpu_layers=50, # Используем GPU насколько возможно
context_length=4096 # Максимальный контекст
)
def generate_text(prompt, max_tokens=512, temperature=0.7, top_p=0.9):
# Форматируем запрос в стиле Mistral
formatted_prompt = f"<s>[INST] {prompt} [/INST]"
# Генерируем ответ
response = model(
formatted_prompt,
max_new_tokens=max_tokens,
temperature=temperature,
top_p=top_p,
repetition_penalty=1.1,
stream=False
)
# Удаляем исходный запрос из ответа
return response.replace(formatted_prompt, "").strip()
custom_css = """
:root {
--primary-color: #4F46E5;
--secondary-color: #6366F1;
--background-color: #F9FAFB;
--surface-color: #FFFFFF;
--text-color: #1F2937;
--border-radius: 10px;
}
body {
background-color: var(--background-color);
}
.container {
max-width: 900px;
margin: auto;
padding-top: 1.5rem;
}
.title {
text-align: center;
color: var(--primary-color);
font-size: 2.2rem;
font-weight: 700;
margin-bottom: 0.5rem;
}
.subtitle {
text-align: center;
color: var(--text-color);
opacity: 0.8;
margin-bottom: 2rem;
}
footer {display: none !important;}
.gradio-container {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}
.gr-button {
border-radius: var(--border-radius) !important;
}
.gr-button-primary {
background-color: var(--primary-color) !important;
}
.gr-input, .gr-textarea {
border-radius: var(--border-radius) !important;
border: 1px solid #E5E7EB !important;
}
.gr-box {
border-radius: var(--border-radius) !important;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;
background-color: var(--surface-color) !important;
padding: 1.5rem !important;
}
.advanced-options {
margin-top: 1rem;
padding: 1rem;
border-radius: var(--border-radius);
background: #F3F4F6;
}
.footer-text {
text-align: center;
margin-top: 1rem;
color: var(--text-color);
opacity: 0.7;
font-size: 0.9rem;
}
"""
with gr.Blocks(css=custom_css) as demo:
with gr.Column(elem_classes="container"):
gr.Markdown("# Devstral Code Assistant", elem_classes="title")
gr.Markdown("Powered by Devstral-Small-2505 - Specialized for code generation", elem_classes="subtitle")
with gr.Box():
prompt = gr.Textbox(
placeholder="Write a function in Python to implement a binary search tree",
label="Your Request",
lines=5
)
with gr.Row():
submit_btn = gr.Button("Generate Code", variant="primary", scale=2)
clear_btn = gr.Button("Clear", scale=1)
with gr.Accordion("Advanced Settings", open=False):
with gr.Row():
with gr.Column():
max_tokens = gr.Slider(
minimum=64, maximum=2048, value=512, step=64,
label="Maximum Output Length"
)
with gr.Column():
temperature = gr.Slider(
minimum=0.1, maximum=1.0, value=0.7, step=0.1,
label="Temperature (Creativity)"
)
with gr.Row():
with gr.Column():
top_p = gr.Slider(
minimum=0.1, maximum=1.0, value=0.9, step=0.05,
label="Top-p (Nucleus Sampling)"
)
output = gr.Textbox(
label="Generated Code",
lines=12,
show_copy_button=True
)
gr.Markdown(
"⚡ Optimized for code generation and technical tasks",
elem_classes="footer-text"
)
submit_btn.click(
generate_text,
inputs=[prompt, max_tokens, temperature, top_p],
outputs=output
)
clear_btn.click(lambda: "", None, prompt)
demo.launch() |