PraneshJs commited on
Commit
5acee3f
·
verified ·
1 Parent(s): 07e498a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import os, shutil, tempfile, re, json
2
  from pathlib import Path
3
  import gradio as gr
4
  from git import Repo
@@ -6,7 +6,7 @@ import requests
6
 
7
  # ---------------- CONFIG ----------------
8
  OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY")
9
- OPENROUTER_MODEL = "nvidia/nemotron-nano-12b-v2-vl:free" # free OpenRouter model
10
  OPENROUTER_URL = "https://openrouter.ai/api/v1/chat/completions"
11
  HEADERS = {
12
  "Authorization": f"Bearer {OPENROUTER_API_KEY}",
@@ -19,8 +19,8 @@ ALLOWED_EXT = {
19
  ".css", ".yml", ".yaml", ".toml", ".ini", ".json"
20
  }
21
  SKIP_DIRS = {
22
- "node_modules", ".git", "dist", "build", "out", "venv", ".venv", "__pycache__",
23
- ".next", ".cache", "target", "bin", "obj", ".idea", ".vscode"
24
  }
25
  MAX_FILE_BYTES = 800_000
26
 
@@ -91,13 +91,13 @@ SYSTEM_PROMPT = (
91
 
92
  def chat_repo(user_msg, chat_history, repo_text):
93
  if not repo_text:
94
- chat_history.append(("", "Please analyze a repository first."))
95
  return chat_history, ""
96
 
97
- # Truncate context for performance (first ~120k chars)
98
- context = repo_text[:120000]
99
  response = openrouter_chat(SYSTEM_PROMPT, user_msg, context)
100
- chat_history.append((user_msg, response))
 
101
  return chat_history, ""
102
 
103
  # ---------------- GRADIO UI ----------------
@@ -124,8 +124,9 @@ with gr.Blocks(title="Repo Chatbot · OpenRouter") as demo:
124
 
125
  status_box = gr.Markdown()
126
 
127
- chatbot = gr.Chatbot(label="Repo Chatbot", height=500)
128
- user_box = gr.Textbox(label="Type your question about the repo and press Enter")
 
129
 
130
  clear_btn = gr.Button("🧹 Clear Chat")
131
 
@@ -139,5 +140,5 @@ with gr.Blocks(title="Repo Chatbot · OpenRouter") as demo:
139
  outputs=[chatbot, user_box])
140
  clear_btn.click(lambda: ([], ""), None, [chatbot, user_box])
141
 
142
- demo.queue(concurrency_count=3)
143
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
1
+ import os, shutil, tempfile, re
2
  from pathlib import Path
3
  import gradio as gr
4
  from git import Repo
 
6
 
7
  # ---------------- CONFIG ----------------
8
  OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY")
9
+ OPENROUTER_MODEL = "nvidia/nemotron-nano-12b-v2-vl:free"
10
  OPENROUTER_URL = "https://openrouter.ai/api/v1/chat/completions"
11
  HEADERS = {
12
  "Authorization": f"Bearer {OPENROUTER_API_KEY}",
 
19
  ".css", ".yml", ".yaml", ".toml", ".ini", ".json"
20
  }
21
  SKIP_DIRS = {
22
+ "node_modules", ".git", "dist", "build", "out", "venv", ".venv",
23
+ "__pycache__", ".next", ".cache", "target", "bin", "obj", ".idea", ".vscode"
24
  }
25
  MAX_FILE_BYTES = 800_000
26
 
 
91
 
92
  def chat_repo(user_msg, chat_history, repo_text):
93
  if not repo_text:
94
+ chat_history.append({"role": "assistant", "content": "❌ Please analyze a repository first."})
95
  return chat_history, ""
96
 
97
+ context = repo_text[:120000] # truncate for token safety
 
98
  response = openrouter_chat(SYSTEM_PROMPT, user_msg, context)
99
+ chat_history.append({"role": "user", "content": user_msg})
100
+ chat_history.append({"role": "assistant", "content": response})
101
  return chat_history, ""
102
 
103
  # ---------------- GRADIO UI ----------------
 
124
 
125
  status_box = gr.Markdown()
126
 
127
+ # Add type='messages' to match new format
128
+ chatbot = gr.Chatbot(label="Repo Chatbot", height=500, type="messages")
129
+ user_box = gr.Textbox(label="Ask something about the repo...")
130
 
131
  clear_btn = gr.Button("🧹 Clear Chat")
132
 
 
140
  outputs=[chatbot, user_box])
141
  clear_btn.click(lambda: ([], ""), None, [chatbot, user_box])
142
 
143
+ demo.queue() # ✅ removed unsupported arg
144
  demo.launch(server_name="0.0.0.0", server_port=7860)