Update app.py
Browse files
app.py
CHANGED
@@ -136,9 +136,6 @@ def get_llm_response(prompt: str, model_name: str = "meta-llama/Llama-2-7b-chat-
|
|
136 |
# Gradio Interface Functions
|
137 |
############################################
|
138 |
|
139 |
-
############################################
|
140 |
-
# Gradio Interface Setup
|
141 |
-
############################################
|
142 |
|
143 |
with gr.Blocks() as demo:
|
144 |
gr.Markdown("# RepoChat - Chat with Repository Files")
|
@@ -148,7 +145,7 @@ with gr.Blocks() as demo:
|
|
148 |
gr.Markdown("### Repository Information")
|
149 |
github_url_input = gr.Textbox(label="GitHub Repository URL", placeholder="https://github.com/username/repository")
|
150 |
load_repo_btn = gr.Button("Load Repository Contents")
|
151 |
-
#
|
152 |
file_dropdown = gr.Dropdown(label="Select a File", interactive=True, value="", choices=[])
|
153 |
repo_content_output = gr.Textbox(label="File Content", interactive=False, lines=10)
|
154 |
with gr.Column(scale=2):
|
@@ -157,7 +154,7 @@ with gr.Blocks() as demo:
|
|
157 |
chat_output = gr.Textbox(label="Chatbot Response", interactive=False, lines=10)
|
158 |
chat_btn = gr.Button("Send Query")
|
159 |
|
160 |
-
# Function to
|
161 |
def load_repo_contents_backend(github_url: str):
|
162 |
try:
|
163 |
owner, repo = extract_repo_info(github_url)
|
@@ -171,39 +168,39 @@ with gr.Blocks() as demo:
|
|
171 |
file_list = [item["path"] for item in tree_data["tree"] if item["type"] == "blob"]
|
172 |
return file_list
|
173 |
|
|
|
174 |
def update_file_dropdown(github_url):
|
175 |
files = load_repo_contents_backend(github_url)
|
176 |
-
|
177 |
-
if isinstance(files, str):
|
178 |
print("Error loading files:", files)
|
179 |
-
return []
|
180 |
print("Files loaded:", files)
|
181 |
-
|
182 |
-
|
|
|
183 |
load_repo_btn.click(fn=update_file_dropdown, inputs=[github_url_input], outputs=[file_dropdown])
|
184 |
|
185 |
-
#
|
186 |
def update_repo_content(github_url, file_choice):
|
187 |
-
if not file_choice
|
188 |
return "No file selected."
|
189 |
try:
|
190 |
file_index = int(file_choice)
|
191 |
except Exception as e:
|
192 |
-
print("Error converting
|
193 |
return "Invalid file selection."
|
194 |
content_tuple = get_file_content_for_choice(github_url, file_index)
|
195 |
if isinstance(content_tuple, str):
|
196 |
-
#
|
197 |
return content_tuple
|
198 |
content, _ = content_tuple
|
199 |
return content
|
200 |
-
|
201 |
file_dropdown.change(fn=update_repo_content, inputs=[github_url_input, file_dropdown], outputs=[repo_content_output])
|
202 |
|
203 |
-
#
|
204 |
def process_chat(github_url, file_choice, chat_query):
|
205 |
-
|
206 |
-
if not file_choice or file_choice == "":
|
207 |
return "Please select a file first."
|
208 |
try:
|
209 |
file_index = int(file_choice)
|
|
|
136 |
# Gradio Interface Functions
|
137 |
############################################
|
138 |
|
|
|
|
|
|
|
139 |
|
140 |
with gr.Blocks() as demo:
|
141 |
gr.Markdown("# RepoChat - Chat with Repository Files")
|
|
|
145 |
gr.Markdown("### Repository Information")
|
146 |
github_url_input = gr.Textbox(label="GitHub Repository URL", placeholder="https://github.com/username/repository")
|
147 |
load_repo_btn = gr.Button("Load Repository Contents")
|
148 |
+
# Initialize dropdown with empty choices and an empty default value.
|
149 |
file_dropdown = gr.Dropdown(label="Select a File", interactive=True, value="", choices=[])
|
150 |
repo_content_output = gr.Textbox(label="File Content", interactive=False, lines=10)
|
151 |
with gr.Column(scale=2):
|
|
|
154 |
chat_output = gr.Textbox(label="Chatbot Response", interactive=False, lines=10)
|
155 |
chat_btn = gr.Button("Send Query")
|
156 |
|
157 |
+
# Function to load repository contents from GitHub.
|
158 |
def load_repo_contents_backend(github_url: str):
|
159 |
try:
|
160 |
owner, repo = extract_repo_info(github_url)
|
|
|
168 |
file_list = [item["path"] for item in tree_data["tree"] if item["type"] == "blob"]
|
169 |
return file_list
|
170 |
|
171 |
+
# Callback to update the file dropdown.
|
172 |
def update_file_dropdown(github_url):
|
173 |
files = load_repo_contents_backend(github_url)
|
174 |
+
if isinstance(files, str): # If there's an error message.
|
|
|
175 |
print("Error loading files:", files)
|
176 |
+
return gr.Dropdown.update(choices=[], value="")
|
177 |
print("Files loaded:", files)
|
178 |
+
# Set the choices but leave value as empty to force user selection.
|
179 |
+
return gr.Dropdown.update(choices=files, value="")
|
180 |
+
|
181 |
load_repo_btn.click(fn=update_file_dropdown, inputs=[github_url_input], outputs=[file_dropdown])
|
182 |
|
183 |
+
# Callback to update the repository content display based on the selected file.
|
184 |
def update_repo_content(github_url, file_choice):
|
185 |
+
if not file_choice:
|
186 |
return "No file selected."
|
187 |
try:
|
188 |
file_index = int(file_choice)
|
189 |
except Exception as e:
|
190 |
+
print("Error converting file choice:", str(e))
|
191 |
return "Invalid file selection."
|
192 |
content_tuple = get_file_content_for_choice(github_url, file_index)
|
193 |
if isinstance(content_tuple, str):
|
194 |
+
# Return error message if one occurred.
|
195 |
return content_tuple
|
196 |
content, _ = content_tuple
|
197 |
return content
|
198 |
+
|
199 |
file_dropdown.change(fn=update_repo_content, inputs=[github_url_input, file_dropdown], outputs=[repo_content_output])
|
200 |
|
201 |
+
# Callback to process the chat query.
|
202 |
def process_chat(github_url, file_choice, chat_query):
|
203 |
+
if not file_choice:
|
|
|
204 |
return "Please select a file first."
|
205 |
try:
|
206 |
file_index = int(file_choice)
|