Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
from github import Github, GithubException
|
3 |
import os
|
4 |
import requests
|
|
|
5 |
|
6 |
# Za艂aduj token z pliku .env lub ustaw bezpo艣rednio
|
7 |
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
|
@@ -15,6 +16,14 @@ def get_file_content(owner, repo_name, path, branch="main"):
|
|
15 |
else:
|
16 |
return f"B艂膮d pobierania pliku: {response.status_code}"
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
def github_tool(
|
20 |
action: str,
|
@@ -33,7 +42,8 @@ def github_tool(
|
|
33 |
labels: str = None, # etykiety oddzielone przecinkami
|
34 |
tag: str = None,
|
35 |
name: str = None, # nazwa release
|
36 |
-
file_url: str = None, # URL pliku do pobrania
|
|
|
37 |
):
|
38 |
"""Narz臋dzie do zarz膮dzania repozytoriami GitHub."""
|
39 |
user = g.get_user()
|
@@ -251,10 +261,40 @@ def github_tool(
|
|
251 |
}
|
252 |
return info # Zwraca s艂ownik z informacjami
|
253 |
|
254 |
-
elif action == "get_file_content":
|
255 |
if not all([owner, repo_name, path]):
|
256 |
raise ValueError("Brakuj膮ce parametry: owner, repo_name, path")
|
257 |
-
return get_file_content(owner, repo_name, path, branch)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
258 |
|
259 |
else:
|
260 |
raise ValueError(f"Nieznana akcja: {action}")
|
@@ -292,7 +332,8 @@ with gr.Blocks() as demo:
|
|
292 |
"list_forks",
|
293 |
"list_files",
|
294 |
"get_repository_info",
|
295 |
-
"get_file_content",
|
|
|
296 |
],
|
297 |
label="Akcja",
|
298 |
)
|
@@ -312,6 +353,7 @@ with gr.Blocks() as demo:
|
|
312 |
tag = gr.Textbox(label="Tag")
|
313 |
release_name = gr.Textbox(label="Nazwa release") # Zmieniona nazwa
|
314 |
file_url = gr.Textbox(label="URL pliku") # Dodane pole
|
|
|
315 |
|
316 |
with gr.Row():
|
317 |
run_button = gr.Button("Wykonaj")
|
@@ -337,6 +379,7 @@ with gr.Blocks() as demo:
|
|
337 |
tag,
|
338 |
release_name, # U偶ycie zmienionej nazwy
|
339 |
file_url, # Dodany argument
|
|
|
340 |
],
|
341 |
outputs=output,
|
342 |
api_name="github_tool"
|
|
|
2 |
from github import Github, GithubException
|
3 |
import os
|
4 |
import requests
|
5 |
+
import re
|
6 |
|
7 |
# Za艂aduj token z pliku .env lub ustaw bezpo艣rednio
|
8 |
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
|
|
|
16 |
else:
|
17 |
return f"B艂膮d pobierania pliku: {response.status_code}"
|
18 |
|
19 |
+
def extract_repo_info(url):
|
20 |
+
"""Wyodr臋bnia nazw臋 u偶ytkownika i repozytorium z linku GitHub."""
|
21 |
+
match = re.search(r"github\.com/([^/]+)/([^/]+)", url)
|
22 |
+
if match:
|
23 |
+
return match.group(1), match.group(2)
|
24 |
+
else:
|
25 |
+
return None, None
|
26 |
+
|
27 |
|
28 |
def github_tool(
|
29 |
action: str,
|
|
|
42 |
labels: str = None, # etykiety oddzielone przecinkami
|
43 |
tag: str = None,
|
44 |
name: str = None, # nazwa release
|
45 |
+
file_url: str = None, # URL pliku do pobrania,
|
46 |
+
repo_url: str = None, # Link do repozytorium
|
47 |
):
|
48 |
"""Narz臋dzie do zarz膮dzania repozytoriami GitHub."""
|
49 |
user = g.get_user()
|
|
|
261 |
}
|
262 |
return info # Zwraca s艂ownik z informacjami
|
263 |
|
264 |
+
elif action == "get_file_content":
|
265 |
if not all([owner, repo_name, path]):
|
266 |
raise ValueError("Brakuj膮ce parametry: owner, repo_name, path")
|
267 |
+
return get_file_content(owner, repo_name, path, branch)
|
268 |
+
|
269 |
+
elif action == "analyze_repository_by_url":
|
270 |
+
if not repo_url:
|
271 |
+
raise ValueError("Brakuj膮cy parametr: repo_url")
|
272 |
+
|
273 |
+
owner, repo_name = extract_repo_info(repo_url)
|
274 |
+
if not owner or not repo_name:
|
275 |
+
raise ValueError("Nieprawid艂owy link do repozytorium")
|
276 |
+
|
277 |
+
try:
|
278 |
+
repo = g.get_repo(f"{owner}/{repo_name}")
|
279 |
+
|
280 |
+
# Pobierz list臋 plik贸w i katalog贸w
|
281 |
+
contents = repo.get_contents("")
|
282 |
+
|
283 |
+
# Iteruj po li艣cie i pobieraj zawarto艣膰 plik贸w
|
284 |
+
file_analyses = []
|
285 |
+
for content in contents:
|
286 |
+
if content.type == "file":
|
287 |
+
file_content = content.decoded_content.decode()
|
288 |
+
file_analyses.append({
|
289 |
+
"name": content.name,
|
290 |
+
"path": content.path,
|
291 |
+
"content": file_content,
|
292 |
+
# Mo偶esz doda膰 tutaj analiz臋 zawarto艣ci pliku
|
293 |
+
})
|
294 |
+
return file_analyses
|
295 |
+
|
296 |
+
except GithubException as e:
|
297 |
+
return f"B艂膮d GitHub: {str(e)}"
|
298 |
|
299 |
else:
|
300 |
raise ValueError(f"Nieznana akcja: {action}")
|
|
|
332 |
"list_forks",
|
333 |
"list_files",
|
334 |
"get_repository_info",
|
335 |
+
"get_file_content",
|
336 |
+
"analyze_repository_by_url",
|
337 |
],
|
338 |
label="Akcja",
|
339 |
)
|
|
|
353 |
tag = gr.Textbox(label="Tag")
|
354 |
release_name = gr.Textbox(label="Nazwa release") # Zmieniona nazwa
|
355 |
file_url = gr.Textbox(label="URL pliku") # Dodane pole
|
356 |
+
repo_url = gr.Textbox(label="Link do repozytorium") # Dodane pole
|
357 |
|
358 |
with gr.Row():
|
359 |
run_button = gr.Button("Wykonaj")
|
|
|
379 |
tag,
|
380 |
release_name, # U偶ycie zmienionej nazwy
|
381 |
file_url, # Dodany argument
|
382 |
+
repo_url, # Dodany argument
|
383 |
],
|
384 |
outputs=output,
|
385 |
api_name="github_tool"
|