File size: 1,432 Bytes
7c377b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31779cc
7c377b6
 
 
 
 
 
 
 
 
64cccc9
7c377b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from agent import CodingAgent

agent = CodingAgent()

def handle_query(message, history):
    response = agent.answer(message)
    history.append((message, response))
    return history, ""

def upload_file(file):
    return agent.ingest_file(file.name)

def clear_memory():
    return agent.clear_context()

def get_info():
    return agent.get_stats()

with gr.Blocks(title="LLaMA-3 Coding Agent") as demo:
    gr.Markdown("# 🦙 TinyLlama Coding Agent\nSupports code Q&A + PDF / code file RAG")

    with gr.Tab("Chat"):
        chatbot = gr.Chatbot()
        with gr.Row():
            msg = gr.Textbox(placeholder="Ask a coding question")
            send = gr.Button("Send")
        send.click(handle_query, [msg, chatbot], [chatbot, msg])
        msg.submit(handle_query, [msg, chatbot], [chatbot, msg])

    with gr.Tab("Upload PDF /code file"):
        file_input = gr.File(label="Upload PDF or Python File", file_types=[".pdf", ".py"])
        upload_btn = gr.Button("Upload")
        output = gr.Textbox()
        upload_btn.click(upload_file, file_input, output)

    with gr.Tab("System"):
        info_btn = gr.Button("Get Info")
        clear_btn = gr.Button("Clear Memory")
        info_box = gr.Textbox()
        status_box = gr.Textbox()
        info_btn.click(get_info, outputs=info_box)
        clear_btn.click(clear_memory, outputs=status_box)

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