Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import logging
|
|
5 |
import time
|
6 |
import os
|
7 |
from datetime import datetime
|
8 |
-
from typing import List, Dict
|
9 |
import requests
|
10 |
import gradio as gr
|
11 |
import atexit
|
@@ -38,7 +38,6 @@ def initialize_logger():
|
|
38 |
return logging.getLogger(__name__)
|
39 |
|
40 |
# Set up environment
|
41 |
-
@spaces.GPU
|
42 |
def initialize_environment(input_file, output_directory):
|
43 |
directories = [LOGS_DIRECTORY, RESOLUTIONS_DIRECTORY, REPOS_DIRECTORY, input_file, output_directory]
|
44 |
for directory in directories:
|
@@ -156,6 +155,32 @@ def handle_issue_selection(token, owner, repo, issue_number, resolution, forked_
|
|
156 |
result = bot.resolve_issue(token, owner, repo, issue_number, resolution, forked_repo)
|
157 |
return result
|
158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
custom_css = """
|
160 |
/* DaisyUI and Tailwind are loaded from CDN */
|
161 |
@import url('https://cdn.jsdelivr.net/npm/[email protected]/dist/full.css');
|
@@ -219,7 +244,7 @@ custom_css = """
|
|
219 |
}
|
220 |
"""
|
221 |
|
222 |
-
def create_gradio_interface(
|
223 |
bot = GitHubBot()
|
224 |
|
225 |
with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
|
@@ -277,18 +302,28 @@ def create_gradio_interface(input_file, output_directory):
|
|
277 |
elem_classes="output-area"
|
278 |
)
|
279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
280 |
gr.HTML("</div></div>") # Close card and container divs
|
281 |
|
282 |
def fetch_issues_handler(token, repo_link):
|
283 |
if not all([token, repo_link]):
|
284 |
-
return gr.Dropdown(choices=["Please provide all required fields"])
|
285 |
|
286 |
owner, repo = repo_link.split('/')[-2:]
|
287 |
issues = bot.fetch_issues(token, owner, repo)
|
288 |
if not issues:
|
289 |
-
return gr.Dropdown(choices=["No issues found or error occurred"])
|
290 |
|
291 |
-
return gr.Dropdown(
|
292 |
choices=[f"#{issue['number']}: {issue['title']}" for issue in issues]
|
293 |
)
|
294 |
|
@@ -303,6 +338,10 @@ def create_gradio_interface(input_file, output_directory):
|
|
303 |
except Exception as e:
|
304 |
return f"Error: {str(e)}"
|
305 |
|
|
|
|
|
|
|
|
|
306 |
# Connect components
|
307 |
fetch_button.click(
|
308 |
fetch_issues_handler,
|
@@ -322,6 +361,12 @@ def create_gradio_interface(input_file, output_directory):
|
|
322 |
outputs=[output_text]
|
323 |
)
|
324 |
|
|
|
|
|
|
|
|
|
|
|
|
|
325 |
return demo
|
326 |
|
327 |
# Cleanup function
|
@@ -347,12 +392,9 @@ if __name__ == "__main__":
|
|
347 |
signal.signal(signal.SIGINT, signal_handler)
|
348 |
signal.signal(signal.SIGTERM, signal_handler)
|
349 |
|
350 |
-
input_file = INPUT_DIRECTORY
|
351 |
-
output_directory = OUTPUT_DIRECTORY
|
352 |
-
|
353 |
# Initialize logger
|
354 |
-
logger = initialize_environment(
|
355 |
|
356 |
# Create Gradio interface
|
357 |
-
demo = create_gradio_interface(
|
358 |
demo.launch()
|
|
|
5 |
import time
|
6 |
import os
|
7 |
from datetime import datetime
|
8 |
+
from typing import List, Dict, Any
|
9 |
import requests
|
10 |
import gradio as gr
|
11 |
import atexit
|
|
|
38 |
return logging.getLogger(__name__)
|
39 |
|
40 |
# Set up environment
|
|
|
41 |
def initialize_environment(input_file, output_directory):
|
42 |
directories = [LOGS_DIRECTORY, RESOLUTIONS_DIRECTORY, REPOS_DIRECTORY, input_file, output_directory]
|
43 |
for directory in directories:
|
|
|
155 |
result = bot.resolve_issue(token, owner, repo, issue_number, resolution, forked_repo)
|
156 |
return result
|
157 |
|
158 |
+
def extract_info_from_url(url: str) -> Dict[str, Any]:
|
159 |
+
info = {}
|
160 |
+
try:
|
161 |
+
response = requests.get(url)
|
162 |
+
response.raise_for_status()
|
163 |
+
info['status_code'] = response.status_code
|
164 |
+
info['headers'] = dict(response.headers)
|
165 |
+
info['content'] = response.text[:500] # Limit content to first 500 characters for brevity
|
166 |
+
|
167 |
+
if 'github.com' in url:
|
168 |
+
parts = url.split('/')
|
169 |
+
if len(parts) > 4:
|
170 |
+
owner = parts[3]
|
171 |
+
repo = parts[4]
|
172 |
+
issues = bot.fetch_issues(github_token, owner, repo)
|
173 |
+
info['issues'] = issues
|
174 |
+
elif 'huggingface.co' in url:
|
175 |
+
# Add Hugging Face specific handling if needed
|
176 |
+
pass
|
177 |
+
|
178 |
+
except requests.HTTPError as e:
|
179 |
+
info['error'] = f"HTTP error: {str(e)}"
|
180 |
+
except Exception as e:
|
181 |
+
info['error'] = f"Error: {str(e)}"
|
182 |
+
return info
|
183 |
+
|
184 |
custom_css = """
|
185 |
/* DaisyUI and Tailwind are loaded from CDN */
|
186 |
@import url('https://cdn.jsdelivr.net/npm/[email protected]/dist/full.css');
|
|
|
244 |
}
|
245 |
"""
|
246 |
|
247 |
+
def create_gradio_interface():
|
248 |
bot = GitHubBot()
|
249 |
|
250 |
with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
|
|
|
302 |
elem_classes="output-area"
|
303 |
)
|
304 |
|
305 |
+
url_textbox = gr.Textbox(
|
306 |
+
label="URL",
|
307 |
+
placeholder="Enter a URL to extract information",
|
308 |
+
elem_classes="input input-bordered input-primary"
|
309 |
+
)
|
310 |
+
extract_button = gr.Button(
|
311 |
+
"Extract Info",
|
312 |
+
elem_classes="button button-primary"
|
313 |
+
)
|
314 |
+
|
315 |
gr.HTML("</div></div>") # Close card and container divs
|
316 |
|
317 |
def fetch_issues_handler(token, repo_link):
|
318 |
if not all([token, repo_link]):
|
319 |
+
return gr.Dropdown.update(choices=["Please provide all required fields"])
|
320 |
|
321 |
owner, repo = repo_link.split('/')[-2:]
|
322 |
issues = bot.fetch_issues(token, owner, repo)
|
323 |
if not issues:
|
324 |
+
return gr.Dropdown.update(choices=["No issues found or error occurred"])
|
325 |
|
326 |
+
return gr.Dropdown.update(
|
327 |
choices=[f"#{issue['number']}: {issue['title']}" for issue in issues]
|
328 |
)
|
329 |
|
|
|
338 |
except Exception as e:
|
339 |
return f"Error: {str(e)}"
|
340 |
|
341 |
+
def extract_info_handler(url):
|
342 |
+
info = extract_info_from_url(url)
|
343 |
+
return info
|
344 |
+
|
345 |
# Connect components
|
346 |
fetch_button.click(
|
347 |
fetch_issues_handler,
|
|
|
361 |
outputs=[output_text]
|
362 |
)
|
363 |
|
364 |
+
extract_button.click(
|
365 |
+
extract_info_handler,
|
366 |
+
inputs=[url_textbox],
|
367 |
+
outputs=[output_text]
|
368 |
+
)
|
369 |
+
|
370 |
return demo
|
371 |
|
372 |
# Cleanup function
|
|
|
392 |
signal.signal(signal.SIGINT, signal_handler)
|
393 |
signal.signal(signal.SIGTERM, signal_handler)
|
394 |
|
|
|
|
|
|
|
395 |
# Initialize logger
|
396 |
+
logger = initialize_environment(INPUT_DIRECTORY, OUTPUT_DIRECTORY)
|
397 |
|
398 |
# Create Gradio interface
|
399 |
+
demo = create_gradio_interface()
|
400 |
demo.launch()
|