Mohd-Shujath commited on
Commit
176cf9b
·
1 Parent(s): 2eac1e6

Deploy fine-tuned driver

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. Qwen3.5-0.8B.Q4_K_M.gguf +3 -0
  3. app.py +96 -0
  4. requirements.txt +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.gguf filter=lfs diff=lfs merge=lfs -text
Qwen3.5-0.8B.Q4_K_M.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a6160a46d97148cacded85a0d46df13fea41afca96fca6d3f14ecd71768cb5b6
3
+ size 541903808
app.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from typing import List, Literal, Optional
3
+ from pydantic import BaseModel, Field
4
+ from fastapi import FastAPI, HTTPException, Header
5
+ import gradio as gr
6
+ from llama_cpp import Llama
7
+
8
+ # -------------------------------------------------------------
9
+ # Configuration & Secret
10
+ # -------------------------------------------------------------
11
+ MODEL_PATH = "Qwen3.5-0.8B.Q4_K_M.gguf"
12
+ API_KEY = os.getenv("API_KEY", "commitcon-secret-2026")
13
+
14
+ print("Loading GGUF model via llama-cpp ...")
15
+ llm = Llama(
16
+ model_path=MODEL_PATH,
17
+ n_ctx=4096,
18
+ n_threads=2,
19
+ verbose=False
20
+ )
21
+ print("Model loaded successfully!")
22
+
23
+ # -------------------------------------------------------------
24
+ # FastAPI App
25
+ # -------------------------------------------------------------
26
+ app = FastAPI(title="CommitCon Sherpa AI Copilot")
27
+
28
+ class HistoryMessage(BaseModel):
29
+ role: Literal["user", "assistant"]
30
+ content: str = Field(min_length=1, max_length=4000)
31
+
32
+ class ChatRequest(BaseModel):
33
+ driver_id: Optional[str] = "DRV_DEFAULT"
34
+ driver_prompt: str = Field(min_length=1, max_length=2000)
35
+ current_zone_id: Optional[str] = None
36
+ history: List[HistoryMessage] = Field(default_factory=list)
37
+
38
+ SYSTEM_PROMPT = (
39
+ "You are Sherpa, an AI driving assistant for the CommitCon ride-hailing repositioning platform in Bengaluru. "
40
+ "Your job is to provide concise, direct, helpful recommendations to drivers about where to reposition for high demand, "
41
+ "earnings, and low traffic delays. Keep your advice practical, realistic, and focused on maximizing their earnings."
42
+ )
43
+
44
+ def run_inference(prompt: str, history: List[dict] = None) -> str:
45
+ messages = [{"role": "system", "content": SYSTEM_PROMPT}]
46
+ if history:
47
+ for m in history:
48
+ messages.append({"role": m["role"], "content": m["content"]})
49
+ messages.append({"role": "user", "content": prompt})
50
+
51
+ response = llm.create_chat_completion(
52
+ messages=messages,
53
+ temperature=0.7,
54
+ max_tokens=512,
55
+ )
56
+ return response["choices"][0]["message"]["content"]
57
+
58
+ @app.get("/")
59
+ def root():
60
+ return {"status": "ok", "service": "CommitCon HF Driver AI Inference Service"}
61
+
62
+ @app.post("/chat")
63
+ def chat_endpoint(payload: ChatRequest, x_api_key: Optional[str] = Header(None)):
64
+ if API_KEY and x_api_key != API_KEY:
65
+ raise HTTPException(status_code=401, detail="Unauthorized: Invalid API Key")
66
+
67
+ formatted_history = [{"role": m.role, "content": m.content} for m in payload.history]
68
+ answer = run_inference(payload.driver_prompt, formatted_history)
69
+
70
+ return {
71
+ "status": "success",
72
+ "answer": answer,
73
+ "model": "project-driver-qwen-gguf",
74
+ "zone_context": payload.current_zone_id
75
+ }
76
+
77
+ # -------------------------------------------------------------
78
+ # Gradio UI Mount (allows testing directly on Hugging Face)
79
+ # -------------------------------------------------------------
80
+ def gradio_chat(user_message, history):
81
+ hist_formatted = []
82
+ if history:
83
+ for user_msg, bot_msg in history:
84
+ hist_formatted.append({"role": "user", "content": user_msg})
85
+ if bot_msg:
86
+ hist_formatted.append({"role": "assistant", "content": bot_msg})
87
+ return run_inference(user_message, hist_formatted)
88
+
89
+ demo = gr.ChatInterface(
90
+ fn=gradio_chat,
91
+ title="🧭 CommitCon Sherpa Driver Copilot",
92
+ description="Fine-tuned Qwen 0.8B Q4_K_M AI Driver Copilot for ride repositioning."
93
+ )
94
+
95
+ # Mount Gradio onto the FastAPI app
96
+ app = gr.mount_gradio_app(app, demo, path="/")
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ llama-cpp-python>=0.2.80
2
+ fastapi>=0.115.0
3
+ pydantic>=2.0.0