Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from huggingface_hub import InferenceClient | |
| # 1. Pilih model coding terbaik yang gratis via API | |
| client = InferenceClient("Qwen/Qwen3-Coder-30B-A3B-Instruct") | |
| def respond(message, history): | |
| # System prompt | |
| system_prompt = "Anda adalah Senior AI Software Architect. Berikan solusi kode yang bersih dan efisien." | |
| messages = [{"role": "system", "content": system_prompt}] | |
| # Perbaikan: Menggunakan format history yang kompatibel dengan Gradio terbaru | |
| for item in history: | |
| # Jika history berisi list [user, bot] | |
| if isinstance(item, (list, tuple)) and len(item) == 2: | |
| messages.append({"role": "user", "content": item[0]}) | |
| messages.append({"role": "assistant", "content": item[1]}) | |
| # Tambahkan pesan user terbaru | |
| messages.append({"role": "user", "content": message}) | |
| response = "" | |
| for chunk in client.chat_completion(messages, max_tokens=8192, stream=True): | |
| response += chunk.choices[0].delta.content or "" | |
| yield response | |
| # 5. UI Gradio | |
| demo = gr.ChatInterface(fn=respond, title="AI Coding Assistant Pribadi") | |
| demo.launch() |