Rushabh147 commited on
Commit
de0bb53
·
1 Parent(s): 0416543

use 0.5B model + ensure polished UI

Browse files
Files changed (2) hide show
  1. app/gradio_app.py +34 -18
  2. config.yaml +1 -1
app/gradio_app.py CHANGED
@@ -1,11 +1,7 @@
1
- """Gradio chat UI - the easiest deploy target (Hugging Face Spaces).
2
-
3
- To deploy on HF Spaces:
4
- 1. Create a new Space (SDK: Gradio).
5
- 2. Push this file as `app.py` at the repo root, plus requirements.txt.
6
- 3. Pick a GPU tier if you want the 7B model; the 1.5B runs on CPU (slowly).
7
 
8
  Locally: python app/gradio_app.py
 
9
  """
10
  from __future__ import annotations
11
 
@@ -27,33 +23,53 @@ def _get_assistant():
27
  return _assistant
28
 
29
 
30
- def respond(message, history, mode, use_repair):
31
  assistant = _get_assistant()
 
32
  if use_repair:
33
  from src.agent.repair_loop import make_repair_generator, repair_loop
34
  gen_fn = make_repair_generator(assistant)
35
  trace = repair_loop(message, gen_fn, check_program_fn=lambda c: c, max_iters=3)
36
- code, note = trace.final_code, f"(repair: {'passed' if trace.success else 'best effort'} in {trace.iterations} iters)"
37
- return f"```python\n{code}\n```\n\n_{note}_"
38
 
39
- result = assistant.generate(message, mode=mode, return_sources=True)
40
  if isinstance(result, tuple):
41
  code, sources = result
42
- src_md = "\n".join(f"- ({s['score']:.2f}) {s['docstring']}" for s in sources)
43
- return f"```python\n{code}\n```\n\n**Retrieved examples:**\n{src_md}"
 
 
44
  return f"```python\n{result}\n```"
45
 
46
 
47
- with gr.Blocks(title="Code Generation Assistant") as demo:
48
- gr.Markdown("# Code Generation Assistant\nDescribe what you want; it writes Python, grounded in CodeSearchNet.")
 
 
 
 
49
  with gr.Row():
50
- mode = gr.Radio(["rag", "baseline"], value="rag", label="Mode")
51
- use_repair = gr.Checkbox(label="Agentic repair (run + self-fix)", value=False)
 
 
 
 
 
 
 
 
 
52
  gr.ChatInterface(
53
  fn=respond,
54
  additional_inputs=[mode, use_repair],
55
- examples=[["Write a function to check if a number is prime."],
56
- ["Parse a CSV file and return a list of dicts."]],
 
 
 
 
57
  cache_examples=False,
58
  )
59
 
 
1
+ """Gradio chat UI — Hugging Face Spaces deploy target.
 
 
 
 
 
2
 
3
  Locally: python app/gradio_app.py
4
+ HF Spaces: set app_file: app/gradio_app.py in README front-matter.
5
  """
6
  from __future__ import annotations
7
 
 
23
  return _assistant
24
 
25
 
26
+ def respond(message: str, history, mode: str, use_repair: bool) -> str:
27
  assistant = _get_assistant()
28
+
29
  if use_repair:
30
  from src.agent.repair_loop import make_repair_generator, repair_loop
31
  gen_fn = make_repair_generator(assistant)
32
  trace = repair_loop(message, gen_fn, check_program_fn=lambda c: c, max_iters=3)
33
+ note = f"repair: {'passed' if trace.success else 'best effort'} in {trace.iterations} iter(s)"
34
+ return f"```python\n{trace.final_code}\n```\n\n_{note}_"
35
 
36
+ result = assistant.generate(message, mode=mode, max_new_tokens=160, return_sources=True)
37
  if isinstance(result, tuple):
38
  code, sources = result
39
+ src_lines = "\n".join(
40
+ f"- `{s['score']:.2f}` {s['docstring']}" for s in sources
41
+ )
42
+ return f"```python\n{code}\n```\n\n**Retrieved examples**\n{src_lines}"
43
  return f"```python\n{result}\n```"
44
 
45
 
46
+ with gr.Blocks(theme=gr.themes.Soft(), title="Code Generation Assistant") as demo:
47
+ gr.Markdown(
48
+ "# Code Generation Assistant\n"
49
+ "Writes Python from a natural-language request, grounded in retrieved "
50
+ "CodeSearchNet examples (RAG)."
51
+ )
52
  with gr.Row():
53
+ mode = gr.Radio(
54
+ ["rag", "baseline"],
55
+ value="rag",
56
+ label="Mode",
57
+ info="RAG conditions the model on retrieved CodeSearchNet examples; baseline is zero-shot.",
58
+ )
59
+ use_repair = gr.Checkbox(
60
+ label="Agentic repair",
61
+ value=False,
62
+ info="Generate → run → read error → self-fix loop (up to 3 iterations).",
63
+ )
64
  gr.ChatInterface(
65
  fn=respond,
66
  additional_inputs=[mode, use_repair],
67
+ examples=[
68
+ ["Write a function to check if a number is prime."],
69
+ ["Parse a CSV file and return a list of dictionaries."],
70
+ ["Reverse a singly linked list."],
71
+ ["Compute the Levenshtein distance between two strings."],
72
+ ],
73
  cache_examples=False,
74
  )
75
 
config.yaml CHANGED
@@ -42,7 +42,7 @@ split:
42
 
43
  models:
44
  embed_model: "sentence-transformers/all-MiniLM-L6-v2"
45
- gen_model: "Qwen/Qwen2.5-Coder-1.5B-Instruct"
46
  top_k: 3
47
 
48
  paths:
 
42
 
43
  models:
44
  embed_model: "sentence-transformers/all-MiniLM-L6-v2"
45
+ gen_model: "Qwen/Qwen2.5-Coder-0.5B-Instruct"
46
  top_k: 3
47
 
48
  paths: