arubaDev commited on
Commit
4ebd9c1
·
verified ·
1 Parent(s): c7c28ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import os
2
  import sqlite3
3
- import time
4
  from datetime import datetime
5
  import gradio as gr
6
  from huggingface_hub import InferenceClient
@@ -11,14 +10,19 @@ from huggingface_hub import InferenceClient
11
  MODELS = {
12
  "Meta LLaMA 3.1 (8B Instruct)": "meta-llama/Llama-3.1-8B-Instruct",
13
  "Mistral 7B Instruct": "mistralai/Mistral-7B-Instruct-v0.3",
 
 
14
  }
15
- HF_TOKEN = os.getenv("HF_TOKEN") # set this in your Space's Secrets
 
16
  DB_PATH = "history.db"
17
 
18
  SYSTEM_DEFAULT = (
19
- "You are a coding assistant. Respond only with clean and complete code "
20
- "unless explanation is explicitly requested. Prefer full CRUD scaffolds, "
21
- "with files, paths, and commands when asked."
 
 
22
  )
23
 
24
  # ---------------------------
@@ -133,7 +137,6 @@ def build_api_messages(session_id: int, system_message: str):
133
  return msgs
134
 
135
  def get_client(model_choice: str):
136
- """Return the right InferenceClient for the chosen model."""
137
  model_id = MODELS.get(model_choice, list(MODELS.values())[0])
138
  return InferenceClient(model_id, token=HF_TOKEN)
139
 
@@ -255,8 +258,7 @@ if not labels:
255
  labels, _ = list_sessions()
256
  default_selected = labels[0] if labels else None
257
 
258
- with gr.Blocks(title="LLaMA/Mistral CRUD Automation (with History)", theme=gr.themes.Soft()) as demo:
259
- # --- Updated CSS to make ALL buttons green ---
260
  gr.HTML("""
261
  <style>
262
  button {
@@ -274,7 +276,7 @@ with gr.Blocks(title="LLaMA/Mistral CRUD Automation (with History)", theme=gr.th
274
  </style>
275
  """)
276
 
277
- gr.Markdown("## 🦙🤖 LLaMA & Mistral CRUD Automation — with Persistent History")
278
 
279
  with gr.Row():
280
  with gr.Column(scale=1, min_width=260):
@@ -311,12 +313,11 @@ with gr.Blocks(title="LLaMA/Mistral CRUD Automation (with History)", theme=gr.th
311
  with gr.Column(scale=3):
312
  chatbot = gr.Chatbot(label="Assistant", height=520, type="messages")
313
  with gr.Row():
314
- user_box = gr.Textbox(placeholder="Describe your CRUD task…", lines=3, scale=5)
315
  with gr.Row():
316
  send_btn = gr.Button("Send ▶️", variant="primary")
317
  regen_btn = gr.Button("Regenerate 🔁", variant="secondary")
318
 
319
- # Interactions
320
  refresh_btn.click(refresh_sessions_cb, outputs=session_list)
321
  new_btn.click(new_chat_cb, outputs=[session_list, chatbot, user_box])
322
  del_btn.click(delete_chat_cb, inputs=session_list, outputs=[session_list, chatbot])
 
1
  import os
2
  import sqlite3
 
3
  from datetime import datetime
4
  import gradio as gr
5
  from huggingface_hub import InferenceClient
 
10
  MODELS = {
11
  "Meta LLaMA 3.1 (8B Instruct)": "meta-llama/Llama-3.1-8B-Instruct",
12
  "Mistral 7B Instruct": "mistralai/Mistral-7B-Instruct-v0.3",
13
+ # Later you can add your fine-tuned backend-focused model here
14
+ # "Backend-Finetuned Model": "your-username/backend-crud-model"
15
  }
16
+
17
+ HF_TOKEN = os.getenv("HF_TOKEN") # Set in your Space's Secrets
18
  DB_PATH = "history.db"
19
 
20
  SYSTEM_DEFAULT = (
21
+ "You are a backend-focused coding assistant. "
22
+ "Always prioritize database, API, authentication, routing, migrations, and CRUD logic. "
23
+ "Provide full backend code scaffolds with files, paths, and commands. "
24
+ "Only include frontend if required for framework integration "
25
+ "(e.g., Laravel Blade, Django templates). Ignore other frontend/UI tasks."
26
  )
27
 
28
  # ---------------------------
 
137
  return msgs
138
 
139
  def get_client(model_choice: str):
 
140
  model_id = MODELS.get(model_choice, list(MODELS.values())[0])
141
  return InferenceClient(model_id, token=HF_TOKEN)
142
 
 
258
  labels, _ = list_sessions()
259
  default_selected = labels[0] if labels else None
260
 
261
+ with gr.Blocks(title="Backend-Focused LLaMA/Mistral CRUD Assistant", theme=gr.themes.Soft()) as demo:
 
262
  gr.HTML("""
263
  <style>
264
  button {
 
276
  </style>
277
  """)
278
 
279
+ gr.Markdown("## 🗄️ LLaMA & Mistral Backend-Focused CRUD Automation — with Persistent History")
280
 
281
  with gr.Row():
282
  with gr.Column(scale=1, min_width=260):
 
313
  with gr.Column(scale=3):
314
  chatbot = gr.Chatbot(label="Assistant", height=520, type="messages")
315
  with gr.Row():
316
+ user_box = gr.Textbox(placeholder="Describe your CRUD/backend task…", lines=3, scale=5)
317
  with gr.Row():
318
  send_btn = gr.Button("Send ▶️", variant="primary")
319
  regen_btn = gr.Button("Regenerate 🔁", variant="secondary")
320
 
 
321
  refresh_btn.click(refresh_sessions_cb, outputs=session_list)
322
  new_btn.click(new_chat_cb, outputs=[session_list, chatbot, user_box])
323
  del_btn.click(delete_chat_cb, inputs=session_list, outputs=[session_list, chatbot])