File size: 3,468 Bytes
04d6f29
 
 
 
 
 
 
 
 
 
 
 
 
 
007def3
 
04d6f29
1c1dc59
04d6f29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
007def3
f01908d
007def3
 
 
 
 
 
 
 
f01908d
 
 
 
 
007def3
 
 
f01908d
 
 
 
 
007def3
 
04d6f29
 
007def3
 
 
 
 
5b0f5f6
007def3
 
 
 
 
 
f01908d
007def3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f01908d
007def3
 
 
 
 
f01908d
 
 
 
007def3
04d6f29
 
 
 
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
import gradio as gr
from huggingface_hub import InferenceClient


def respond(
    message,
    history: list[dict[str, str]],
    system_message,
    max_tokens,
    temperature,
    top_p,
    hf_token: gr.OAuthToken,
):
    """
    Myanmar Coding Assistant - amk-coder-v2
    Powered by HuggingFace Inference API
    """
    client = InferenceClient(token=hf_token.token, model="amkyawdev/amk-coder-v2")

    messages = [{"role": "system", "content": system_message}]
    messages.extend(history)
    messages.append({"role": "user", "content": message})

    response = ""

    for message in client.chat_completion(
        messages,
        max_tokens=max_tokens,
        stream=True,
        temperature=temperature,
        top_p=top_p,
    ):
        choices = message.choices
        token = ""
        if len(choices) and choices[0].delta.content:
            token = choices[0].delta.content
        response += token
        yield response


# Enhanced Gradio UI
with gr.Blocks() as demo:
    gr.Markdown("""
    # πŸ€– amk-coder-v2
    ### Myanmar Coding Assistant | Powered by Qwen2.5-Coder-1.5B
    
    πŸ‡²πŸ‡² α€™α€Όα€”α€Ία€™α€¬α€˜α€¬α€žα€¬α€…α€€α€¬α€Έα€”α€Ύα€„α€·α€Ί English α€”α€Ύα€…α€Ία€α€―α€œα€―α€Άα€Έα€α€½α€„α€Ί code α€›α€±α€Έα€•α€±α€Έα€•α€«α€žα€Šα€Ί
    """)
    
    gr.Markdown("""
    ### ✨ Features
    - πŸ‡²πŸ‡² **Myanmar Support** - Full Myanmar Unicode text support
    - πŸ’» **Code Generation** - Python, JavaScript, C++, Java, and more
    - πŸ› **Debugging** - Bug detection and fixes
    - πŸ“– **Code Explanation** - Line-by-line explanations
    """)
    
    gr.Markdown("""
    ### πŸ’‘ Example Prompts
    - πŸ‡²πŸ‡² `Python function တစ်ခုရေးပါ။ list sorting α€œα€―α€•α€Ία€•α€±α€Έα€•α€«α‹`
    - πŸ‡²πŸ‡² `JavaScript α€”α€²α€· API call ရေးပါ`
    - πŸ‡¬πŸ‡§ `Write a Python function to reverse a string`
    - πŸ› `Fix this: print('Hello' + 5)`
    """)
    
    with gr.Sidebar():
        gr.LoginButton()
        gr.Markdown("""
        ### βš™οΈ Settings
        Adjust generation parameters below
        """)
    
    gr.ChatInterface(
        respond,
        additional_inputs=[
            gr.Textbox(
                value="""You are amk-coder-v2, a helpful Myanmar coding assistant.
- Respond in the same language as the user (Myanmar or English)
- Provide clean, well-commented code
- Explain code when helpful""",
                label="System Prompt",
                lines=4
            ),
            gr.Slider(
                minimum=64,
                maximum=2048,
                value=512,
                step=64,
                label="Max New Tokens"
            ),
            gr.Slider(
                minimum=0.1,
                maximum=1.0,
                value=0.2,
                step=0.1,
                label="Temperature (lower = more focused)"
            ),
            gr.Slider(
                minimum=0.1,
                maximum=1.0,
                value=0.95,
                step=0.05,
                label="Top-p (nucleus sampling)"
            ),
        ],
        chatbot=gr.Chatbot(height=450),
        title="",
        description="",
    )

    gr.Markdown("""
    ---
    **amk-coder-v2** | Fine-tuned from Qwen2.5-Coder-1.5B
    πŸ‡²πŸ‡² Made with ❀️ for Myanmar Developers
    [πŸ“¦ Model Card](https://huggingface.co/amkyawdev/amk-coder-v2) Β· Apache-2.0 License
    """)


if __name__ == "__main__":
    demo.launch()