Spaces:
Sleeping
Sleeping
File size: 3,337 Bytes
ea9e2cb a5c1d2f ea9e2cb a5c1d2f ea9e2cb a5c1d2f ea9e2cb a5c1d2f ea9e2cb a5c1d2f ea9e2cb a5c1d2f ea9e2cb a5c1d2f ea9e2cb a5c1d2f ea9e2cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
import gradio as gr
from scripts.github_analyzer import GitHubAnalyzer
from scripts.topic_list import TOPIC_LIST
analyzer = GitHubAnalyzer()
async def process_url(
url: str,
main_cat: str,
sub_cat: str,
use_gpu: bool
) -> tuple[str, str, str]:
"""
Process GitHub URL and generate topics
Args:
url: GitHub repository URL
main_cat: Main category for classification
sub_cat: Sub-category for classification
use_gpu: Whether to use GPU for processing
Returns:
Tuple of (readme_topics, code_topics, dependencies)
"""
try:
if not all([url, main_cat, sub_cat]):
return "Please select all categories", "", ""
analyzer.set_device("cuda" if use_gpu else "cpu")
response = await analyzer.analyze_repository(url, main_cat, sub_cat)
if not response.success:
return response.errors[0].message, "", ""
# Modified output format: only keywords without scores
readme_topics = " ".join([
f"#{topic['topic'].lower()}"
for topic in response.data["readme_topics"]
])
code_topics = " ".join([
f"#{topic['topic'].lower()}"
for topic in response.data["code_topics"]
])
dependencies = " ".join([
f"#{dep.lower()}"
for dep in response.data["dependencies"]
])
return readme_topics, code_topics, dependencies
except Exception as e:
return f"Error: {str(e)}", "", ""
def create_interface():
"""Create and configure the Gradio interface"""
with gr.Blocks() as demo:
gr.Markdown("# Enhanced GitHub Topic Generator")
with gr.Row():
url_input = gr.Textbox(
label="GitHub URL",
placeholder="Enter GitHub repository URL"
)
with gr.Row():
main_category = gr.Dropdown(
choices=[None] + list(TOPIC_LIST.keys()),
label="Main Category",
value=None
)
sub_category = gr.Dropdown(
choices=[],
label="Sub Category"
)
with gr.Row():
use_gpu = gr.Checkbox(
label="Use GPU (Check if you have CUDA-capable GPU)",
value=False
)
with gr.Row():
generate_btn = gr.Button("Generate Topics")
with gr.Row():
readme_topics = gr.Textbox(label="README Topics")
code_topics = gr.Textbox(label="Code Analysis Topics")
dependencies = gr.Textbox(label="Dependencies")
def update_sub_category(main_cat):
"""Update sub-category choices based on main category selection"""
return gr.Dropdown(
choices=list(TOPIC_LIST[main_cat].keys()) if main_cat else []
)
main_category.change(
update_sub_category,
inputs=main_category,
outputs=sub_category
)
generate_btn.click(
process_url,
inputs=[url_input, main_category, sub_category, use_gpu],
outputs=[readme_topics, code_topics, dependencies]
)
return demo
if __name__ == "__main__":
demo = create_interface()
demo.launch(share=True) |