Skip to content

Commit df33800

Browse files
authored
CodeGen Gradio UI Enhancements (#1904)
Signed-off-by: okhleif-IL <omar.khleif@intel.com>
1 parent 40e44df commit df33800

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

CodeGen/ui/gradio/codegen_ui_gradio.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,24 @@
4646

4747

4848
# Define the functions that will be used in the app
49+
50+
51+
def add_to_history(prompt, history):
52+
history.append([prompt["text"], ""])
53+
return history, ""
54+
55+
4956
def conversation_history(prompt, index, use_agent, history):
5057
print(f"Generating code for prompt: {prompt} using index: {index} and use_agent is {use_agent}")
51-
history.append([prompt, ""])
52-
response_generator = generate_code(prompt, index, use_agent)
58+
history = add_to_history(prompt, history)[0]
59+
response_generator = generate_code(prompt["text"], index, use_agent)
5360
for token in response_generator:
5461
history[-1][-1] += token
55-
yield history
62+
yield history, ""
63+
64+
65+
def clear_history():
66+
return ""
5667

5768

5869
def upload_media(media, index=None, chunk_size=1500, chunk_overlap=100):
@@ -287,19 +298,32 @@ def get_file_names(files):
287298
# Define UI components
288299
with gr.Blocks() as ui:
289300
with gr.Tab("Code Generation"):
290-
gr.Markdown("### Generate Code from Natural Language")
291-
chatbot = gr.Chatbot(label="Chat History")
292-
prompt_input = gr.Textbox(label="Enter your query")
293-
with gr.Column():
294-
with gr.Row(equal_height=True):
301+
with gr.Row():
302+
with gr.Column(scale=2):
295303
database_dropdown = gr.Dropdown(choices=get_indices(), label="Select Index", value="None", scale=10)
296304
db_refresh_button = gr.Button("Refresh Dropdown", scale=0.1)
297305
db_refresh_button.click(update_indices_dropdown, outputs=database_dropdown)
298306
use_agent = gr.Checkbox(label="Use Agent", container=False)
299307

300-
generate_button = gr.Button("Generate Code")
301-
generate_button.click(
302-
conversation_history, inputs=[prompt_input, database_dropdown, use_agent, chatbot], outputs=chatbot
308+
with gr.Column(scale=9):
309+
gr.Markdown("### Generate Code from Natural Language")
310+
chatbot = gr.Chatbot(label="Chat History")
311+
with gr.Row(equal_height=True):
312+
with gr.Column(scale=8):
313+
prompt_input = gr.MultimodalTextbox(
314+
show_label=False, interactive=True, placeholder="Enter your query", sources=[]
315+
)
316+
with gr.Column(scale=1, min_width=150):
317+
with gr.Row(elem_id="buttons") as button_row:
318+
clear_btn = gr.Button(value="🗑️ Clear", interactive=True)
319+
clear_btn.click(clear_history, None, chatbot)
320+
321+
prompt_input.submit(add_to_history, inputs=[prompt_input, chatbot], outputs=[chatbot, prompt_input])
322+
323+
prompt_input.submit(
324+
conversation_history,
325+
inputs=[prompt_input, database_dropdown, use_agent, chatbot],
326+
outputs=[chatbot, prompt_input],
303327
)
304328

305329
with gr.Tab("Resource Management"):
@@ -315,7 +339,7 @@ def get_file_names(files):
315339
)
316340
with gr.Column(scale=3):
317341
file_upload = gr.File(label="Upload Files", file_count="multiple")
318-
url_input = gr.Textbox(label="Media to be ingested (Append URL's in a new line)")
342+
url_input = gr.Textbox(label="Media to be ingested. Append URL's in a new line (Shift + Enter)")
319343
upload_button = gr.Button("Upload", variant="primary")
320344
upload_status = gr.Textbox(label="Upload Status")
321345
file_upload.change(get_file_names, inputs=file_upload, outputs=url_input)

0 commit comments

Comments
 (0)