jyo01 commited on
Commit
b2bf078
·
verified ·
1 Parent(s): 6438d63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -290,7 +290,6 @@ def load_repo_contents_backend(github_url: str):
290
 
291
  # demo.launch(share=True)
292
 
293
-
294
  with gr.Blocks() as demo:
295
  gr.Markdown("# RepoChat - Chat with Repository Files")
296
 
@@ -299,27 +298,29 @@ with gr.Blocks() as demo:
299
  gr.Markdown("### Repository Information")
300
  github_url_input = gr.Textbox(label="GitHub Repository URL", placeholder="https://github.com/username/repository")
301
  load_repo_btn = gr.Button("Load Repository Contents")
 
302
  file_dropdown = gr.Dropdown(label="Select a File", interactive=True, value="", choices=[])
303
- repo_content_output = gr.Textbox(label="File Content", interactive=False, lines=10)
304
  with gr.Column(scale=2):
305
  gr.Markdown("### Chat Interface")
306
- chat_query_input = gr.Textbox(label="Your Query", placeholder="Type your query here")
307
- # Use Chatbot component for conversation history
308
  chat_output = gr.Chatbot(label="Chat Conversation")
 
309
  chat_btn = gr.Button("Send Query")
310
 
311
- # Callback to update file dropdown
312
  def update_file_dropdown(github_url):
313
  files = load_repo_contents_backend(github_url)
314
  if isinstance(files, str):
315
  print("Error loading files:", files)
316
  return gr.update(choices=[], value="")
317
  print("Files loaded:", files)
 
318
  return gr.update(choices=files, value="")
319
-
320
  load_repo_btn.click(fn=update_file_dropdown, inputs=[github_url_input], outputs=[file_dropdown])
321
 
322
- # Callback to update repository content when a file is selected.
323
  def update_repo_content(github_url, file_choice):
324
  if not file_choice:
325
  return "No file selected."
@@ -328,20 +329,21 @@ with gr.Blocks() as demo:
328
 
329
  file_dropdown.change(fn=update_repo_content, inputs=[github_url_input, file_dropdown], outputs=[repo_content_output])
330
 
331
- # Callback to process the chat query. 'history' is an initial empty list.
332
  def process_chat(github_url, file_choice, chat_query, history):
333
  if not file_choice:
334
  history.append(("System", "Please select a file first."))
335
- return history
336
  response = chat_with_file(github_url, file_choice, chat_query)
337
  history.append((chat_query, response))
338
- return history
339
 
340
- # Initialize an empty conversation history
341
  conversation_history = gr.State([])
342
-
343
- chat_btn.click(fn=process_chat,
344
- inputs=[github_url_input, file_dropdown, chat_query_input, conversation_history],
345
- outputs=[chat_output, conversation_history])
346
 
347
- demo.launch(share=True)
 
 
 
 
 
 
 
290
 
291
  # demo.launch(share=True)
292
 
 
293
  with gr.Blocks() as demo:
294
  gr.Markdown("# RepoChat - Chat with Repository Files")
295
 
 
298
  gr.Markdown("### Repository Information")
299
  github_url_input = gr.Textbox(label="GitHub Repository URL", placeholder="https://github.com/username/repository")
300
  load_repo_btn = gr.Button("Load Repository Contents")
301
+ # Dropdown: no pre-selection.
302
  file_dropdown = gr.Dropdown(label="Select a File", interactive=True, value="", choices=[])
303
+ repo_content_output = gr.Textbox(label="File Content", interactive=False, lines=50)
304
  with gr.Column(scale=2):
305
  gr.Markdown("### Chat Interface")
306
+ # Use Chatbot component for conversation appearance.
 
307
  chat_output = gr.Chatbot(label="Chat Conversation")
308
+ chat_query_input = gr.Textbox(label="Your Query", placeholder="Type your query here")
309
  chat_btn = gr.Button("Send Query")
310
 
311
+ # Callback to update file dropdown choices.
312
  def update_file_dropdown(github_url):
313
  files = load_repo_contents_backend(github_url)
314
  if isinstance(files, str):
315
  print("Error loading files:", files)
316
  return gr.update(choices=[], value="")
317
  print("Files loaded:", files)
318
+ # Do not pre-select any file.
319
  return gr.update(choices=files, value="")
320
+
321
  load_repo_btn.click(fn=update_file_dropdown, inputs=[github_url_input], outputs=[file_dropdown])
322
 
323
+ # Callback to update repository content display when a file is selected.
324
  def update_repo_content(github_url, file_choice):
325
  if not file_choice:
326
  return "No file selected."
 
329
 
330
  file_dropdown.change(fn=update_repo_content, inputs=[github_url_input, file_dropdown], outputs=[repo_content_output])
331
 
332
+ # Callback to process the chat query and update conversation history.
333
  def process_chat(github_url, file_choice, chat_query, history):
334
  if not file_choice:
335
  history.append(("System", "Please select a file first."))
336
+ return history, history
337
  response = chat_with_file(github_url, file_choice, chat_query)
338
  history.append((chat_query, response))
339
+ return history, history
340
 
 
341
  conversation_history = gr.State([])
 
 
 
 
342
 
343
+ chat_btn.click(
344
+ fn=process_chat,
345
+ inputs=[github_url_input, file_dropdown, chat_query_input, conversation_history],
346
+ outputs=[chat_output, conversation_history]
347
+ )
348
+
349
+ demo.launch(share=True, server_port=7862)