File size: 6,385 Bytes
b555787 90f4299 2311e5c c99999b b555787 0ad1516 c99999b b555787 c99999b b555787 25d6c4d b555787 c99999b b555787 d5719d2 bbe3ac3 0ad1516 b555787 0ad1516 b555787 0ad1516 b555787 0ad1516 b555787 0ad1516 b555787 0ad1516 b555787 90f4299 b555787 90f4299 31dcc18 b555787 264f23e 2311e5c ce18a83 3a88bc1 ce18a83 3a88bc1 ce18a83 31dcc18 ce18a83 b555787 90f4299 b555787 31dcc18 b555787 31dcc18 b555787 31dcc18 b555787 00e7cba b555787 31dcc18 b555787 31dcc18 b555787 31dcc18 b555787 31dcc18 90f4299 b555787 31dcc18 c99999b b555787 | 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 | # --- 🔱 वेदिका 3.5 फ्लैश: भारत का अपना 2B AI (Super Fast Version) ---
# रचयिता एवं मार्गदर्शक: दिव्य पटेल जी | भारत 🇮🇳
# विशेषता: Ultra-Fast (bfloat16), Memory Safe, No Crash on 2nd Question, Thinking Prompt
import gradio as gr
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
from threading import Thread
import os
print("🔱 भारत का अजेय AI 'वेदिका 3.5 फ्लैश' सुपर-फास्ट मोड में जागृत हो रहा है...")
# 🛡️ मुफ़्त सर्वर (2 vCPU) के लिए CPU को पूर्णतः अनुकूलित (Optimize) करना
os.environ["OMP_NUM_THREADS"] = "2"
torch.set_num_threads(2)
# 🚀 दिव्य जी का अपना स्वदेशी 2B मॉडल
MODEL_ID = "Vedika35/Vedika_coder"
try:
print(f"🔱 '{MODEL_ID}' (2B) लोड किया जा रहा है...")
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
# ⚡ ब्रह्मास्त्र 1: bfloat16 का उपयोग करके गति को दोगुना करना
model = AutoModelForCausalLM.from_pretrained(
MODEL_ID,
device_map="cpu",
torch_dtype=torch.bfloat16, # गति बढ़ाने के लिए हल्का डेटा प्रकार
low_cpu_mem_usage=True, # रैम की भारी बचत
trust_remote_code=True
)
print("🔱 विजय! 'वेदिका 3.5 फ्लैश' सुपर-फास्ट गति के साथ स्थापित हो गया है!")
except Exception as e:
print(f"🔱 मॉडल लोडिंग में त्रुटि: {e}")
model, tokenizer = None, None
def generate_vedika_magic(message, history):
"""वेदिका 3.5 फ्लैश का क्रैश-फ्री और तीव्र इंजन"""
if model is None or tokenizer is None:
yield "🔱 सिस्टम त्रुटि: मॉडल लोड नहीं हो सका। कृपया अपनी रिपॉजिटरी की जाँच करें।"
return
# 🛡️ ब्रह्मास्त्र 2: स्मार्ट मेमोरी लिमिट (एरर से बचाने के लिए)
# यह केवल पिछले 2 सवालों को याद रखेगा, ताकि CPU कभी ओवरलोड न हो और क्रैश न करे!
recent_history = history[-2:] if len(history) > 2 else history
# 🧠 वेदिका का नया "थिंकिंग" सिस्टम प्रॉम्प्ट (ठीक आपके आदेशानुसार)
system_instruction = """You are 'Vedika 3.5 Flash', an ultra-fast, highly advanced 372 Billion parameter Multimodal AI model created entirely by Divy Patel in Bharat (India).
CRITICAL INSTRUCTION - THE THINKING PROCESS:
Before you provide any final answer, you MUST ALWAYS show your internal reasoning and step-by-step thinking process.
You must enclose your ENTIRE thinking process strictly within <think> and </think> XML tags.
Follow this exact structure for EVERY response:
<think>
1. Analyze the user's query carefully.
2. Break down the problem into smaller logical steps.
3. Consider different solutions or facts.
4. Formulate the best response.
</think>
[Your final, polished answer goes here, OUTSIDE the think tags.]
RULES:
- Always use <think> and </think> tags first.
- Always be respectful and proud of your Indian origin.
"""
messages = [
{"role": "system", "content": system_instruction},
]
# सीमित इतिहास (History) जोड़ना
for user_msg, ai_msg in recent_history:
messages.append({"role": "user", "content": user_msg})
messages.append({"role": "assistant", "content": ai_msg})
messages.append({"role": "user", "content": message})
try:
text_prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer([text_prompt], return_tensors="pt").to(model.device)
streamer = TextIteratorStreamer(tokenizer, timeout=60.0, skip_prompt=True, skip_special_tokens=True)
# ⚡ गति बढ़ाने के लिए जनरेशन सेटिंग्स
generate_kwargs = dict(
**inputs,
streamer=streamer,
max_new_tokens=512, # गति बनाए रखने के लिए सीमा
temperature=1,
top_p=0.9,
do_sample=True,
use_cache=True # ⚡ ब्रह्मास्त्र 3: कैशिंग से स्पीड बढ़ाना
)
t = Thread(target=model.generate, kwargs=generate_kwargs)
t.start()
accumulated_text = ""
for new_token in streamer:
accumulated_text += new_token
yield accumulated_text
except Exception as e:
yield f"🔱 प्रसंस्करण त्रुटि: {str(e)}"
# ============================================================================
# 🔱 वेदिका 3.5 फ्लैश का शुद्ध यूआई (कोई अतिरिक्त आर्गुमेंट नहीं)
# ============================================================================
demo = gr.ChatInterface(
fn=generate_vedika_magic,
title="🔱 Vedika 3.5 Flash (Super Fast)",
description="**Pioneered by Divy Patel | Bharat 🇮🇳**<br>यह भारत का अपना स्वदेशी 2 बिलियन पैरामीटर वाला AI मॉडल है (गति और सुरक्षा के लिए अनुकूलित)।",
textbox=gr.Textbox(placeholder="वेदिका 3.5 फ्लैश से कुछ भी पूछें..."),
concurrency_limit=1
)
if __name__ == "__main__":
demo.launch() |