Spaces:
Sleeping
Sleeping
File size: 5,858 Bytes
7864210 a43554c 5f5212c a43554c 374046b 7864210 06b7369 a43554c dfa4338 06b7369 5f5212c a43554c 06b7369 5f5212c 06b7369 5f5212c 2833e1d 5f5212c a43554c 374046b 06b7369 374046b a43554c 06b7369 a43554c 06b7369 a43554c 7864210 06b7369 a43554c 7864210 06b7369 2833e1d a43554c 06b7369 a43554c 06b7369 5f5212c a43554c 7864210 a43554c 7864210 06b7369 a43554c 374046b 06b7369 dfa4338 2833e1d 5f5212c a43554c 2833e1d 5f5212c 2833e1d a43554c dfa4338 06b7369 2833e1d a43554c 2833e1d 5f5212c 2833e1d 5f5212c 2833e1d 06b7369 5f5212c a43554c 06b7369 7864210 a43554c 2833e1d 06b7369 5f5212c a43554c 5f5212c a43554c 2833e1d 06b7369 2833e1d 06b7369 2833e1d a43554c 06b7369 2833e1d 7864210 06b7369 | 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 | import gradio as gr
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer, BitsAndBytesConfig
from threading import Thread
import os
# आदरणीय श्रीमान, आपके स्वयं के मॉडल 'Vedika35/Vedika_coder' को स्मृति में लोड करने की सुरक्षित विधि।
MODEL_ID = "Vedika35/Vedika_coder"
# स्मृति अनुकूलन (Memory Optimization) के लिए 4-bit क्वायंटाइजेशन
quantization_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.float16,
bnb_4bit_quant_type="nf4",
bnb_4bit_use_double_quant=True,
)
print(f"आदरणीय श्रीमान, {MODEL_ID} को लोड किया जा रहा है। कृपया प्रतीक्षा करें...")
# टोकनाइज़र और मॉडल की लोडिंग
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
model = AutoModelForCausalLM.from_pretrained(
MODEL_ID,
quantization_config=quantization_config,
device_map="auto",
trust_remote_code=True
)
def vedika_generate(message, history, system_prompt):
"""
यह जनरेशन फंक्शन अब ग्राडियो के सबसे सुरक्षित और स्थिर फॉर्मेट (List of Lists) का उपयोग करता है।
यहाँ 'history' का फॉर्मेट है: [[user_msg, bot_msg], [user_msg, bot_msg], ...]
"""
messages = [{"role": "system", "content": system_prompt}]
# पुरानी यादें (History) जोड़ना
for user_msg, bot_msg in history:
if user_msg:
messages.append({"role": "user", "content": user_msg})
if bot_msg:
messages.append({"role": "assistant", "content": bot_msg})
# वर्तमान संदेश
messages.append({"role": "user", "content": message})
# इनपुट को टोकनाइज़ करना
input_ids = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
return_tensors="pt"
).to(model.device)
# बिजली जैसी तेज़ स्ट्रीमिंग (Lightning Fast Streaming)
streamer = TextIteratorStreamer(tokenizer, timeout=30.0, skip_prompt=True, skip_special_tokens=True)
generate_kwargs = dict(
input_ids=input_ids,
streamer=streamer,
max_new_tokens=4096,
do_sample=True,
temperature=0.2, # कोडिंग के लिए सटीकता
top_p=0.95,
)
t = Thread(target=model.generate, kwargs=generate_kwargs)
t.start()
# शब्दों को लाइव स्ट्रीम करना
partial_text = ""
for new_text in streamer:
partial_text += new_text
yield partial_text
# कस्टम सीएसएस (Custom CSS)
custom_css = """
body, .gradio-container { background-color: #050505 !important; color: #F0F0F0 !important; }
.message-wrap { font-family: 'Inter', sans-serif !important; }
footer { visibility: hidden !important; }
#header-title h1 {
background: linear-gradient(90deg, #FFFFFF, #3b82f6);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
font-size: 2.8rem;
font-weight: 900;
text-align: center;
}
"""
# ध्यान दें: ग्राडियो ६.० के अनुसार यहाँ से theme और css हटा दिए गए हैं
with gr.Blocks() as demo:
with gr.Row():
gr.Markdown("# 🔱 Vedika 3.5 Coder", elem_id="header-title")
gr.Markdown("### भारत के गौरवशाली और समर्थ कोडर के लिए समर्पित | Created by Divy Patel")
with gr.Accordion("⚙️ System Parameters (Advanced)", open=False):
sys_input = gr.Textbox(
label="Core System Prompt",
value="You are Vedika 3.5, an elite coding AI created by Divy Patel. Identify only as Vedika. Provide extremely direct, clean, and production-ready code in Markdown. Always respect India.",
lines=2
)
# ध्यान दें: यहाँ से type="messages" हटा दिया गया है ताकि कोई TypeError न आए
chatbot = gr.Chatbot(label="Vedika Core Console", height=600)
with gr.Row():
msg_input = gr.Textbox(
label="Execution Command",
placeholder="श्रीमान, अपना कोडिंग कार्य यहाँ लिखें...",
scale=8
)
submit_btn = gr.Button("⚡ Execute", scale=2, variant="primary")
def respond(message, history, system_prompt):
# सुरक्षित फॉर्मेट में हिस्ट्री अपडेट करना
history.append([message, ""])
yield "", history
for char in vedika_generate(message, history[:-1], system_prompt):
history[-1][1] = char
yield "", history
# इवेंट्स
msg_input.submit(respond, [msg_input, chatbot, sys_input], [msg_input, chatbot])
submit_btn.click(respond, [msg_input, chatbot, sys_input], [msg_input, chatbot])
if __name__ == "__main__":
# ध्यान दें: ग्राडियो ६.० की चेतावनी (Warning) के अनुसार theme और css को launch() के अंदर भेजा गया है
demo.queue(default_concurrency_limit=5).launch(
theme=gr.themes.Monochrome(),
css=custom_css
) |