paulcalzada commited on
Commit
1316d52
·
1 Parent(s): 3f24fde

api script and removed retriever info

Browse files
Files changed (2) hide show
  1. app.py +2 -11
  2. deepv_api_tutorial.py +61 -0
app.py CHANGED
@@ -80,20 +80,11 @@ with gr.Blocks(title="DeepV for RTL (Model-Agnostic)", theme=gr.themes.Soft()) a
80
  elem_id="verilog-output"
81
  )
82
  copy_button = gr.Button("📋", variant="secondary", elem_id="copy-button")
83
-
84
- with gr.Tab("Retrieved Items (names + scores)"):
85
- retrieved_list = gr.Textbox(
86
- label="Retriever summary",
87
- lines=8,
88
- interactive=False
89
- )
90
- with gr.Tab("Preview of Retrieved Context (raw)"):
91
- retrieved_raw = gr.HighlightedText(label="(first K documents)", combine_adjacent=True)
92
 
93
  with gr.Row():
94
  clear_btn = gr.ClearButton(
95
  value="Clear All",
96
- components=[spec, api_key, out_code, retrieved_list, retrieved_raw]
97
  )
98
 
99
  def copy_to_clipboard_fn(text):
@@ -113,7 +104,7 @@ with gr.Blocks(title="DeepV for RTL (Model-Agnostic)", theme=gr.themes.Soft()) a
113
  ).then(
114
  fn=run_generation,
115
  inputs=[spec, use_rag, top_k, model_choice, api_key, temperature, top_p, max_new_tokens],
116
- outputs=[out_code, retrieved_list, retrieved_raw],
117
  ).then(
118
  fn=hide_loading,
119
  inputs=[],
 
80
  elem_id="verilog-output"
81
  )
82
  copy_button = gr.Button("📋", variant="secondary", elem_id="copy-button")
 
 
 
 
 
 
 
 
 
83
 
84
  with gr.Row():
85
  clear_btn = gr.ClearButton(
86
  value="Clear All",
87
+ components=[spec, api_key, out_code]
88
  )
89
 
90
  def copy_to_clipboard_fn(text):
 
104
  ).then(
105
  fn=run_generation,
106
  inputs=[spec, use_rag, top_k, model_choice, api_key, temperature, top_p, max_new_tokens],
107
+ outputs=[out_code],
108
  ).then(
109
  fn=hide_loading,
110
  inputs=[],
deepv_api_tutorial.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from gradio_client import Client
2
+ import os
3
+
4
+ # This will be the URL of DeepV's Gradio App
5
+ GRADIO_APP_URL = "paulcalzada/DeepV" # Replace with your actual app URL
6
+
7
+ try:
8
+ # Initialize the Gradio client
9
+ client = Client(GRADIO_APP_URL)
10
+ print("DeepV Gradio client initialized successfully!")
11
+
12
+ # input design spec to prompt LLM
13
+ design_spec = "Create me a 2x1 multiplexer with the following module header: module mux2x1(input wire a, input wire b, input wire sel, output wire y);"
14
+
15
+ # number of retrieved documents for RAG
16
+ k_value = 1
17
+
18
+ # Set if you would like to use DeepV's RAG technique
19
+ rag_enabled = True
20
+
21
+ # Select your model: gpt-4o, gpt-4o-mini, gpt-4.1, gpt-5-chat-latest
22
+ model_name = "gpt-4o"
23
+
24
+ openai_key = "" # Replace with your actual OpenAI API key
25
+ # Note: Your OpenAI API key is only active for this session and is not saved or stored.
26
+
27
+ # Customize some generation parameters (temperature, top_p, max_tokens)
28
+ temp_value = 0.5
29
+ top_p_value = 0.9
30
+ max_tokens = 1024
31
+
32
+ # --- Call the Gradio app's API endpoint ---
33
+ # The `predict` method corresponds to a component's action.
34
+ response = client.predict(
35
+ design_spec,
36
+ rag_enabled,
37
+ k_value,
38
+ model_name,
39
+ openai_key,
40
+ temp_value,
41
+ top_p_value,
42
+ max_tokens,
43
+ api_name="/run_generation" # Assuming 'run_generation' is exposed as an API
44
+ )
45
+
46
+ # --- Process the response ---
47
+ # The response will be a list or tuple of outputs, in the order
48
+ # defined by the `outputs` parameter of your `run_btn.click` function.
49
+ # Your outputs are: [out_code, retrieved_list, retrieved_raw]
50
+
51
+ generated_code = response[0]
52
+
53
+ print("\n--- API Call Successful! ---")
54
+ print("\nGenerated Verilog Code:")
55
+ print("-------------------------")
56
+ print(generated_code)
57
+
58
+ except Exception as e:
59
+ print(f"An error occurred: {e}")
60
+ print("Please ensure your Gradio app is running and the URL is correct.")
61
+ print("You might also need to find the correct `fn_index` if the API call fails.")