| """ |
| AmkyawDev AI Agent - Gradio Interface |
| Simple chat interface for AI code generation |
| """ |
|
|
| import gradio as gr |
| from typing import Iterator, List |
|
|
| |
| SYSTEM_PROMPT = """You are an expert AI Developer Agent. |
| You help users write code, debug issues, and explain programming concepts. |
| Provide clean, well-documented code with explanations.""" |
|
|
| |
| chat_history: List[dict] = [] |
|
|
|
|
| def predict(message: str, history: List[list]) -> Iterator[str]: |
| """Process user message and generate response""" |
| global chat_history |
| |
| |
| history.append([message, None]) |
| |
| |
| responses = [ |
| "I've analyzed your request. Here's what I can help you with:\n\n" |
| "1. **Code Generation** - Tell me what you want to build\n" |
| "2. **Debugging** - Share your code and I'll find the issue\n" |
| "3. **Explanations** - Ask me about any programming concept\n\n" |
| "What would you like me to help you with?", |
| |
| "## Available Commands\n\n" |
| "- `Create a [type] app` - Generate a new application\n" |
| "- `Fix this code` - Debug your code\n" |
| "- `Explain [topic]` - Teach you something new\n" |
| "- `Refactor [code]` - Improve existing code", |
| |
| "## Getting Started\n\n" |
| "Try these examples:\n" |
| "1. 'Create a Python calculator'\n" |
| "2. 'Build a REST API with FastAPI'\n" |
| "3. 'Write a web scraper in Python'\n\n" |
| "I'm ready to help! 🚀", |
| ] |
| |
| |
| response = responses[len(history) % len(responses)] |
| |
| |
| for word in response.split(): |
| yield word + " " |
| history[-1][1] = word + " " |
| |
| chat_history.append({"role": "user", "content": message}) |
| chat_history.append({"role": "assistant", "content": response}) |
|
|
|
|
| |
| with gr.Blocks( |
| title="AmkyawDev AI Agent", |
| theme=gr.themes.Soft(), |
| css=""" |
| .gradio-container { |
| background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); |
| } |
| .message { |
| background: rgba(255,255,255,0.1) !important; |
| border-radius: 12px; |
| } |
| """ |
| ) as demo: |
| gr.Markdown(""" |
| # 🤖 AmkyawDev AI Agent |
| |
| Your AI-powered developer assistant |
| |
| --- |
| """) |
| |
| chat = gr.Chatbot( |
| placeholder="Ask me anything about coding...", |
| show_label=False, |
| bubble_full_width=False, |
| height=500, |
| ) |
| |
| with gr.Row(): |
| msg = gr.Textbox( |
| placeholder="Type your message here...", |
| show_label=False, |
| scale=4, |
| ) |
| submit = gr.Button("Send", variant="primary", scale=1) |
| |
| gr.Examples( |
| examples=[ |
| ["Create a Python calculator"], |
| ["Build a REST API with FastAPI"], |
| ["Write a web scraper in Python"], |
| ["Explain React hooks"], |
| ], |
| inputs=msg, |
| ) |
| |
| |
| submit_event = submit.click( |
| predict, |
| inputs=[msg, chat], |
| outputs=[chat], |
| ) |
| submit_event = msg.submit( |
| predict, |
| inputs=[msg, chat], |
| outputs=[chat], |
| ) |
| |
| msg.submit(lambda: "", None, msg) |
|
|
| |
| demo.launch() |