Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files
app.py
CHANGED
|
@@ -1,10 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from scripts.github_analyzer import GitHubAnalyzer
|
| 3 |
from scripts.topic_list import TOPIC_LIST
|
| 4 |
-
from scripts.error_handler import ErrorHandler
|
| 5 |
|
| 6 |
analyzer = GitHubAnalyzer()
|
| 7 |
-
error_handler = ErrorHandler()
|
| 8 |
|
| 9 |
async def process_url(
|
| 10 |
url: str,
|
|
@@ -12,13 +10,21 @@ async def process_url(
|
|
| 12 |
sub_cat: str,
|
| 13 |
use_gpu: bool
|
| 14 |
) -> tuple[str, str, str]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
try:
|
| 16 |
if not all([url, main_cat, sub_cat]):
|
| 17 |
-
|
| 18 |
-
url,
|
| 19 |
-
"Please select all categories"
|
| 20 |
-
)
|
| 21 |
-
return response.errors[0].message, "", ""
|
| 22 |
|
| 23 |
analyzer.set_device("cuda" if use_gpu else "cpu")
|
| 24 |
response = await analyzer.analyze_repository(url, main_cat, sub_cat)
|
|
@@ -26,13 +32,14 @@ async def process_url(
|
|
| 26 |
if not response.success:
|
| 27 |
return response.errors[0].message, "", ""
|
| 28 |
|
|
|
|
| 29 |
readme_topics = " ".join([
|
| 30 |
-
f"#{topic['topic'].lower()}
|
| 31 |
for topic in response.data["readme_topics"]
|
| 32 |
])
|
| 33 |
|
| 34 |
code_topics = " ".join([
|
| 35 |
-
f"#{topic['topic'].lower()}
|
| 36 |
for topic in response.data["code_topics"]
|
| 37 |
])
|
| 38 |
|
|
@@ -44,10 +51,10 @@ async def process_url(
|
|
| 44 |
return readme_topics, code_topics, dependencies
|
| 45 |
|
| 46 |
except Exception as e:
|
| 47 |
-
|
| 48 |
-
return response.errors[0].message, "", ""
|
| 49 |
|
| 50 |
def create_interface():
|
|
|
|
| 51 |
with gr.Blocks() as demo:
|
| 52 |
gr.Markdown("# Enhanced GitHub Topic Generator")
|
| 53 |
|
|
@@ -83,6 +90,7 @@ def create_interface():
|
|
| 83 |
dependencies = gr.Textbox(label="Dependencies")
|
| 84 |
|
| 85 |
def update_sub_category(main_cat):
|
|
|
|
| 86 |
return gr.Dropdown(
|
| 87 |
choices=list(TOPIC_LIST[main_cat].keys()) if main_cat else []
|
| 88 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from scripts.github_analyzer import GitHubAnalyzer
|
| 3 |
from scripts.topic_list import TOPIC_LIST
|
|
|
|
| 4 |
|
| 5 |
analyzer = GitHubAnalyzer()
|
|
|
|
| 6 |
|
| 7 |
async def process_url(
|
| 8 |
url: str,
|
|
|
|
| 10 |
sub_cat: str,
|
| 11 |
use_gpu: bool
|
| 12 |
) -> tuple[str, str, str]:
|
| 13 |
+
"""
|
| 14 |
+
Process GitHub URL and generate topics
|
| 15 |
+
|
| 16 |
+
Args:
|
| 17 |
+
url: GitHub repository URL
|
| 18 |
+
main_cat: Main category for classification
|
| 19 |
+
sub_cat: Sub-category for classification
|
| 20 |
+
use_gpu: Whether to use GPU for processing
|
| 21 |
+
|
| 22 |
+
Returns:
|
| 23 |
+
Tuple of (readme_topics, code_topics, dependencies)
|
| 24 |
+
"""
|
| 25 |
try:
|
| 26 |
if not all([url, main_cat, sub_cat]):
|
| 27 |
+
return "Please select all categories", "", ""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
analyzer.set_device("cuda" if use_gpu else "cpu")
|
| 30 |
response = await analyzer.analyze_repository(url, main_cat, sub_cat)
|
|
|
|
| 32 |
if not response.success:
|
| 33 |
return response.errors[0].message, "", ""
|
| 34 |
|
| 35 |
+
# Modified output format: only keywords without scores
|
| 36 |
readme_topics = " ".join([
|
| 37 |
+
f"#{topic['topic'].lower()}"
|
| 38 |
for topic in response.data["readme_topics"]
|
| 39 |
])
|
| 40 |
|
| 41 |
code_topics = " ".join([
|
| 42 |
+
f"#{topic['topic'].lower()}"
|
| 43 |
for topic in response.data["code_topics"]
|
| 44 |
])
|
| 45 |
|
|
|
|
| 51 |
return readme_topics, code_topics, dependencies
|
| 52 |
|
| 53 |
except Exception as e:
|
| 54 |
+
return f"Error: {str(e)}", "", ""
|
|
|
|
| 55 |
|
| 56 |
def create_interface():
|
| 57 |
+
"""Create and configure the Gradio interface"""
|
| 58 |
with gr.Blocks() as demo:
|
| 59 |
gr.Markdown("# Enhanced GitHub Topic Generator")
|
| 60 |
|
|
|
|
| 90 |
dependencies = gr.Textbox(label="Dependencies")
|
| 91 |
|
| 92 |
def update_sub_category(main_cat):
|
| 93 |
+
"""Update sub-category choices based on main category selection"""
|
| 94 |
return gr.Dropdown(
|
| 95 |
choices=list(TOPIC_LIST[main_cat].keys()) if main_cat else []
|
| 96 |
)
|