import gradio as gr import time import threading import logging from gradio.themes.utils import sizes from main import run_repository_ranking import agent # --------------------------- # Global Logging Buffer Setup # --------------------------- LOG_BUFFER = [] LOG_BUFFER_LOCK = threading.Lock() class BufferLogHandler(logging.Handler): def emit(self, record): log_entry = self.format(record) with LOG_BUFFER_LOCK: LOG_BUFFER.append(log_entry) root_logger = logging.getLogger() if not any(isinstance(h, BufferLogHandler) for h in root_logger.handlers): handler = BufferLogHandler() formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") handler.setFormatter(formatter) root_logger.addHandler(handler) def filter_logs(logs): filtered = [] last_was_fetching = False for log in logs: if "HTTP Request:" in log: if not last_was_fetching: filtered.append("Fetching repositories...") last_was_fetching = True else: filtered.append(log) last_was_fetching = False return filtered def parse_result_to_html(raw_result: str, num_results: int) -> (str, list): """ Parses the raw string output from run_repository_ranking to an HTML table. Only the top N results are displayed. Returns (html, repo_names) """ entries = raw_result.strip().split("Final Rank:") entries = entries[1:num_results+1] # Use only the first N entries if not entries: return ("
No repositories found for your query.
", []) html = """Rank | Title | Link | Combined Score |
---|---|---|---|
{data.get('Final Rank', '')} | {data.get('Title', '')} | GitHub | {data.get('Combined Score', '')} |
Processing your request. Please wait...
", [] for status, details, repos in stream_lite_workflow(topic, num_results): yield status, details, repos # --------------------------- # App UI Setup Using Gradio Soft Theme with Centered Layout # --------------------------- with gr.Blocks( theme=gr.themes.Soft(text_size=sizes.text_md), title="DeepGit Lite", css=""" /* Center header and footer */ #header { text-align: center; margin-bottom: 20px; } #main-container { max-width: 800px; margin: auto; } #footer { text-align: center; margin-top: 20px; } """ ) as demo: gr.Markdown( """
✨ DeepGit Lite is the lightweight pro version of DeepGit.
It harnesses advanced deep semantic search to explore GitHub repositories and deliver curated results.
Under the hood, it leverages a hybrid ranking approach combining dense retrieval, BM25 scoring, and cross-encoder re-ranking for optimal discovery.
New! 🗨️ After searching, you can chat with the agent about any repository you find.
The conversation agent runs in the background and is ready to answer your questions about setup, usage, or details for each repo.
Just click "Go to Chat" after your search, select a repository, and start your conversation!
🚀 Check out the full DeepGit version on GitHub and ⭐ Star DeepGit on GitHub!