Update app.py
Browse files
app.py
CHANGED
@@ -180,6 +180,9 @@ def chat_with_file(github_url: str, file_choice: int, user_query: str):
|
|
180 |
############################################
|
181 |
# Gradio Interface Setup
|
182 |
############################################
|
|
|
|
|
|
|
183 |
|
184 |
with gr.Blocks() as demo:
|
185 |
gr.Markdown("# RepoChat - Chat with Repository Files")
|
@@ -189,7 +192,8 @@ with gr.Blocks() as demo:
|
|
189 |
gr.Markdown("### Repository Information")
|
190 |
github_url_input = gr.Textbox(label="GitHub Repository URL", placeholder="https://github.com/username/repository")
|
191 |
load_repo_btn = gr.Button("Load Repository Contents")
|
192 |
-
|
|
|
193 |
repo_content_output = gr.Textbox(label="File Content", interactive=False, lines=10)
|
194 |
with gr.Column(scale=2):
|
195 |
gr.Markdown("### Chat Interface")
|
@@ -197,14 +201,16 @@ with gr.Blocks() as demo:
|
|
197 |
chat_output = gr.Textbox(label="Chatbot Response", interactive=False, lines=10)
|
198 |
chat_btn = gr.Button("Send Query")
|
199 |
|
200 |
-
#
|
201 |
def update_file_dropdown(github_url):
|
202 |
files = load_repo_contents(github_url)
|
|
|
|
|
203 |
return files
|
204 |
|
205 |
load_repo_btn.click(fn=update_file_dropdown, inputs=[github_url_input], outputs=[file_dropdown])
|
206 |
|
207 |
-
#
|
208 |
def update_repo_content(github_url, file_choice):
|
209 |
if not file_choice:
|
210 |
return "No file selected."
|
@@ -217,10 +223,11 @@ with gr.Blocks() as demo:
|
|
217 |
|
218 |
file_dropdown.change(fn=update_repo_content, inputs=[github_url_input, file_dropdown], outputs=[repo_content_output])
|
219 |
|
220 |
-
#
|
221 |
def process_chat(github_url, file_choice, chat_query):
|
222 |
return chat_with_file(github_url, int(file_choice), chat_query)
|
223 |
|
224 |
chat_btn.click(fn=process_chat, inputs=[github_url_input, file_dropdown, chat_query_input], outputs=[chat_output])
|
225 |
|
226 |
-
demo.launch()
|
|
|
|
180 |
############################################
|
181 |
# Gradio Interface Setup
|
182 |
############################################
|
183 |
+
############################################
|
184 |
+
# Gradio Interface Setup
|
185 |
+
############################################
|
186 |
|
187 |
with gr.Blocks() as demo:
|
188 |
gr.Markdown("# RepoChat - Chat with Repository Files")
|
|
|
192 |
gr.Markdown("### Repository Information")
|
193 |
github_url_input = gr.Textbox(label="GitHub Repository URL", placeholder="https://github.com/username/repository")
|
194 |
load_repo_btn = gr.Button("Load Repository Contents")
|
195 |
+
# Set allow_custom_value=True to avoid errors when the selected value is not in the choices.
|
196 |
+
file_dropdown = gr.Dropdown(label="Select a File", interactive=True, allow_custom_value=True)
|
197 |
repo_content_output = gr.Textbox(label="File Content", interactive=False, lines=10)
|
198 |
with gr.Column(scale=2):
|
199 |
gr.Markdown("### Chat Interface")
|
|
|
201 |
chat_output = gr.Textbox(label="Chatbot Response", interactive=False, lines=10)
|
202 |
chat_btn = gr.Button("Send Query")
|
203 |
|
204 |
+
# Function to update the file dropdown based on the GitHub repository URL.
|
205 |
def update_file_dropdown(github_url):
|
206 |
files = load_repo_contents(github_url)
|
207 |
+
if isinstance(files, str) and files.startswith("Error"):
|
208 |
+
return []
|
209 |
return files
|
210 |
|
211 |
load_repo_btn.click(fn=update_file_dropdown, inputs=[github_url_input], outputs=[file_dropdown])
|
212 |
|
213 |
+
# Function to update the repository content display when a file is selected.
|
214 |
def update_repo_content(github_url, file_choice):
|
215 |
if not file_choice:
|
216 |
return "No file selected."
|
|
|
223 |
|
224 |
file_dropdown.change(fn=update_repo_content, inputs=[github_url_input, file_dropdown], outputs=[repo_content_output])
|
225 |
|
226 |
+
# Function to process the chat query.
|
227 |
def process_chat(github_url, file_choice, chat_query):
|
228 |
return chat_with_file(github_url, int(file_choice), chat_query)
|
229 |
|
230 |
chat_btn.click(fn=process_chat, inputs=[github_url_input, file_dropdown, chat_query_input], outputs=[chat_output])
|
231 |
|
232 |
+
demo.launch(share=True)
|
233 |
+
|