Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| """ | |
| Repository Input Component | |
| This module provides the UI component for entering a GitHub repository URL. | |
| """ | |
| import gradio as gr | |
| import re | |
| import logging | |
| logger = logging.getLogger(__name__) | |
| def validate_github_url(url): | |
| """ | |
| Validate that the input is a proper GitHub repository URL. | |
| Args: | |
| url (str): The URL to validate. | |
| Returns: | |
| str or None: Error message if invalid, None if valid. | |
| """ | |
| if not url: | |
| return None | |
| # Basic GitHub URL pattern | |
| pattern = r'^https?://github\.com/[\w.-]+/[\w.-]+/?$' | |
| if not re.match(pattern, url): | |
| return "Please enter a valid GitHub repository URL" | |
| return None | |
| def create_repo_input(): | |
| """ | |
| Create the repository input component. | |
| Returns: | |
| tuple: (repo_url, github_token, submit_btn) - The repository URL input, GitHub token input, and submit button. | |
| """ | |
| with gr.Group(): | |
| gr.Markdown("### 📂 GitHub Repository") | |
| repo_url = gr.Textbox( | |
| label="Repository URL", | |
| placeholder="https://github.com/username/repository", | |
| info="Enter the URL of a GitHub repository", | |
| ) | |
| github_token = gr.Textbox( | |
| label="GitHub Token (Optional)", | |
| placeholder="For private repositories only", | |
| info="Required only for private repositories", | |
| type="password", | |
| visible=True | |
| ) | |
| submit_btn = gr.Button( | |
| value="Analyze Repository", | |
| variant="primary", | |
| scale=0, | |
| ) | |
| # Add validation for GitHub URL format | |
| error_box = gr.Textbox( | |
| label="Error", | |
| visible=True, | |
| interactive=False, | |
| container=False, | |
| show_label=False | |
| ) | |
| repo_url.change( | |
| fn=validate_github_url, | |
| inputs=[repo_url], | |
| outputs=[error_box], | |
| show_progress=False | |
| ) | |
| return repo_url, github_token, submit_btn |