paulcalzada commited on
Commit
9592ee8
·
verified ·
1 Parent(s): 3eb27e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -27
app.py CHANGED
@@ -1,56 +1,41 @@
1
  import os
2
- from pathlib import Path
3
  import gradio as gr
4
- from huggingface_hub import snapshot_download, hf_hub_download
5
  import importlib.util
6
 
7
- # This is the path to your private dataset repository on Hugging Face Hub
8
  PRIVATE_DATASET_ID = os.getenv("PRIVATE_DATASET_ID")
9
  HF_TOKEN = os.getenv("HF_TOKEN")
10
  INDEX_SUBDIR = os.getenv("INDEX_SUBDIR", ".")
11
 
12
  # --- Core Logic Download and Import ---
13
  try:
14
- # First, download the core agent code from the private repo
15
  AGENT_CODE_PATH = hf_hub_download(
16
  repo_id=PRIVATE_DATASET_ID,
17
- filename="deepv_core.py", # The file containing your VerilogAgent class
18
- repo_type="dataset", # Ensure this is 'dataset' to match your repo type
19
  token=HF_TOKEN
20
  )
21
- # Dynamically load the agent module from the downloaded file
22
  spec = importlib.util.spec_from_file_location("deepv_core_module", AGENT_CODE_PATH)
23
  agent_module = importlib.util.module_from_spec(spec)
24
  spec.loader.exec_module(agent_module)
25
 
26
- # Now you can access the functions and classes from the private module
27
- VerilogAgent = agent_module.VerilogAgent
28
  run_generation = agent_module.run_generation
29
- get_vectorstore_path = agent_module.get_vectorstore_path
30
- ensure_index_downloaded = agent_module.ensure_index_downloaded
31
 
32
  except Exception as e:
33
- # Handle the error gracefully if the private repo can't be accessed
34
  def show_error(*args):
35
- return f"// ERROR: Failed to load core agent code. Check your Hugging Face token and private dataset configuration. Details: {e}", "", []
36
-
37
- # Keep a lightweight global cache so we don’t reload embeddings on every click
38
- _VECTORSTORE_PATH = None
39
 
40
  # --- Gradio UI setup below ---
41
  with gr.Blocks(title="DeepV for RTL (Model-Agnostic)") as demo:
42
  gr.Markdown("## DeepV for RTL Code Generation — Model-Agnostic (Bring Your Own API Key)")
43
-
44
  with gr.Row():
45
  with gr.Column(scale=2):
46
  with gr.Row():
47
  model_choice = gr.Dropdown(
48
- choices=[
49
- "gpt-4o",
50
- "gpt-4o-mini",
51
- "gpt-4.1",
52
- "gpt-5-chat-latest",
53
- ],
54
  value="gpt-4o",
55
  label="Model"
56
  )
@@ -61,7 +46,7 @@ with gr.Blocks(title="DeepV for RTL (Model-Agnostic)") as demo:
61
  **Note:** Your API key is used for the current session only and is not saved or stored.
62
  """
63
  )
64
-
65
  spec = gr.Textbox(
66
  label="Design Specification (natural language or I/O contract)",
67
  placeholder="e.g., 8-bit UART transmitter with baud rate generator ...",
@@ -70,7 +55,7 @@ with gr.Blocks(title="DeepV for RTL (Model-Agnostic)") as demo:
70
  with gr.Row():
71
  use_rag = gr.Checkbox(value=True, label="Use Retrieval (RAG)")
72
  top_k = gr.Slider(1, 10, value=3, step=1, label="Top-K retrieved examples")
73
-
74
  with gr.Accordion("Generation Settings", open=False):
75
  temperature = gr.Slider(0.0, 1.5, value=0.2, step=0.05, label="Temperature")
76
  top_p = gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="Top-p")
@@ -85,7 +70,6 @@ with gr.Blocks(title="DeepV for RTL (Model-Agnostic)") as demo:
85
  interactive=False,
86
  placeholder="// Your Verilog code will appear here"
87
  )
88
- # Add a dedicated copy button
89
  copy_button = gr.Button("Copy Code", variant="secondary")
90
 
91
  with gr.Tab("Retrieved Items (names + scores)"):
@@ -123,7 +107,6 @@ with gr.Blocks(title="DeepV for RTL (Model-Agnostic)") as demo:
123
  """
124
  )
125
 
126
-
127
  if __name__ == "__main__":
128
  if 'agent_module' in locals():
129
  demo.launch()
 
1
  import os
 
2
  import gradio as gr
3
+ from huggingface_hub import hf_hub_download
4
  import importlib.util
5
 
6
+ # --- Private Repository Information ---
7
  PRIVATE_DATASET_ID = os.getenv("PRIVATE_DATASET_ID")
8
  HF_TOKEN = os.getenv("HF_TOKEN")
9
  INDEX_SUBDIR = os.getenv("INDEX_SUBDIR", ".")
10
 
11
  # --- Core Logic Download and Import ---
12
  try:
 
13
  AGENT_CODE_PATH = hf_hub_download(
14
  repo_id=PRIVATE_DATASET_ID,
15
+ filename="deepv_core.py",
16
+ repo_type="dataset",
17
  token=HF_TOKEN
18
  )
 
19
  spec = importlib.util.spec_from_file_location("deepv_core_module", AGENT_CODE_PATH)
20
  agent_module = importlib.util.module_from_spec(spec)
21
  spec.loader.exec_module(agent_module)
22
 
23
+ # Now you can access the functions directly from the private module
 
24
  run_generation = agent_module.run_generation
 
 
25
 
26
  except Exception as e:
 
27
  def show_error(*args):
28
+ return f"// ERROR: Failed to load core agent code. Details: {e}", "", []
 
 
 
29
 
30
  # --- Gradio UI setup below ---
31
  with gr.Blocks(title="DeepV for RTL (Model-Agnostic)") as demo:
32
  gr.Markdown("## DeepV for RTL Code Generation — Model-Agnostic (Bring Your Own API Key)")
33
+
34
  with gr.Row():
35
  with gr.Column(scale=2):
36
  with gr.Row():
37
  model_choice = gr.Dropdown(
38
+ choices=["gpt-4o", "gpt-4o-mini", "gpt-4.1", "gpt-5-chat-latest"],
 
 
 
 
 
39
  value="gpt-4o",
40
  label="Model"
41
  )
 
46
  **Note:** Your API key is used for the current session only and is not saved or stored.
47
  """
48
  )
49
+
50
  spec = gr.Textbox(
51
  label="Design Specification (natural language or I/O contract)",
52
  placeholder="e.g., 8-bit UART transmitter with baud rate generator ...",
 
55
  with gr.Row():
56
  use_rag = gr.Checkbox(value=True, label="Use Retrieval (RAG)")
57
  top_k = gr.Slider(1, 10, value=3, step=1, label="Top-K retrieved examples")
58
+
59
  with gr.Accordion("Generation Settings", open=False):
60
  temperature = gr.Slider(0.0, 1.5, value=0.2, step=0.05, label="Temperature")
61
  top_p = gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="Top-p")
 
70
  interactive=False,
71
  placeholder="// Your Verilog code will appear here"
72
  )
 
73
  copy_button = gr.Button("Copy Code", variant="secondary")
74
 
75
  with gr.Tab("Retrieved Items (names + scores)"):
 
107
  """
108
  )
109
 
 
110
  if __name__ == "__main__":
111
  if 'agent_module' in locals():
112
  demo.launch()