| 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() |