File size: 1,642 Bytes
9e94085
c727824
 
 
 
 
9e94085
 
 
c727824
9e94085
c727824
9e94085
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c727824
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
# Gemma 4 Coder + Agentic - VPS Ollama Interface
import os, json, httpx, asyncio
os.environ.setdefault("DO_NOT_TRACK", "1")
os.environ.setdefault("GRADIO_ANALYTICS_ENABLED", "False")
import gradio as gr

VPS = "http://187.124.226.128:8000"
HF = os.getenv("HF_TOKEN","")
MODELS = {"V1 Coder":"gemma4-coder","V2 Agentic":"gemma4-v2"}

async def sh(c):
    try:
        r = await httpx.AsyncClient(timeout=120).get(f"{VPS}/api/exec",params={"cmd":c})
        return r.json().get("stdout","")[:3000]
    except Exception as e: return f"Error:{e}"

async def chat(m,p,s=""):
    ms = []
    if s: ms.append({"role":"system","content":s})
    ms.append({"role":"user","content":p})
    pl = json.dumps({"model":m,"messages":ms,"stream":0})
    r = await sh("curl -s --max-time 120 http://127.0.0.1:11435/api/chat -d '" + pl + "'")
    try: return json.loads(r).get("message",{}).get("content",r)
    except: return r

async def respond(m,h,mod,sys):
    return (await chat(MODELS[mod],m,sys)) if m else ""

with gr.Blocks() as demo:
    gr.Markdown("# Gemma 4 12B Coder + Agentic")
    with gr.Tab("Chat"):
        mc = gr.Dropdown(choices=list(MODELS.keys()), value="V2 Agentic")
        sp = gr.Textbox(label="System", lines=2)
        cb = gr.Chatbot(type="messages", height=400)
        tx = gr.Textbox(label="Message")
        tx.submit(respond,[tx,cb,mc,sp],tx)
    with gr.Tab("Tools"):
        gr.Markdown("### Web Search")
        sq = gr.Textbox()
        sb = gr.Button("Search")
        so = gr.Markdown()
        sb.click(lambda q:sh("curl -s 'http://127.0.0.1:43092/search?q="+q.replace(" ","%")+"&format=json'"),sq,so)
demo.launch()