File size: 2,420 Bytes
3f6f3a0
61f02e6
3f6f3a0
61f02e6
 
 
 
 
 
3f6f3a0
 
61f02e6
 
 
 
 
 
3f6f3a0
61f02e6
 
3f6f3a0
 
61f02e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3f6f3a0
61f02e6
 
 
 
 
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
import gradio as gr
from huggingface_hub import InferenceClient

# ==============================================================================
# Step 1: Hugging Face chya Fast Server (API) la connect karne
# Yane model tumchya space madhye download hot nahi, direct GPU varun chalte.
# Model: Qwen2.5-Coder-32B-Instruct (Ha ek khup powerful aani motha Coding AI aahe)
# ==============================================================================
client = InferenceClient("Qwen/Qwen2.5-Coder-32B-Instruct")


# ==============================================================================
# Step 2: Chatbot che function banavne
# He function user cha message gheun, API la pathavun, uttar parat anel.
# ==============================================================================
def fast_coding_bot(message, history):
    # System la sangne ki tu ek coding expert aahes
    messages = [
        {"role": "system", "content": "You are a professional coding assistant. Always provide clean, efficient, and well-explained code."},
        {"role": "user", "content": message}
    ]
    
    response = ""
    # Streaming dware uttar anane (jase ChatGPT madhye yete)
    try:
        for msg in client.chat_completion(messages, max_tokens=1024, stream=True, temperature=0.1):
            token = msg.choices[0].delta.content
            if token:
                response += token
                yield response
    except Exception as e:
        yield f"Error: {e}"


# ==============================================================================
# Step 3: Gradio cha wapar karun User Interface (UI) banavne
# ==============================================================================
demo = gr.ChatInterface(
    fn=fast_coding_bot,
    title="🚀 Super-Fast Coding AI (GPU Powered)",
    description="Ha AI Hugging Face chya powerful GPU server var chalat aahe. Mhanun ha fast aani smart aahe. Mala kontahi coding prashna vichara!",
    examples=[
        "Write a Python code for a simple snake game using pygame.",
        "Create a responsive HTML and CSS code for a portfolio website.",
        "How to connect to a MySQL database in Java?"
    ],
    theme="soft"
)


# ==============================================================================
# Step 4: App chalu karne
# ==============================================================================
if __name__ == "__main__":
    demo.launch()