import gradio as gr
import time
import threading
import logging
from src.deepgit_lite import run_deepgit_lite
# ---------------------------
# 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
# ---------------------------
# Title, Favicon & Description
# ---------------------------
favicon_html = """
DeepGit Lite Research Agent
"""
title = """
DeepGit Lite
⚙️ A lightweight GitHub research agent for deep semantic search and ranking.
"""
description = """
DeepGit Lite is a streamlined version of DeepGit designed for fast semantic search on GitHub repositories. It enhances your query, retrieves repositories using dense retrieval via FAISS, filters by star count, combines scores based on semantic similarity and popularity, and then provides a concise justification for the top results.
"""
consent_text = """
By using DeepGit Lite, you consent to temporary processing of your query for semantic search and ranking purposes.
⭐ Star us on GitHub if you find this tool useful! GitHub
"""
footer = """
Made with ❤️ by Zamal
"""
# ---------------------------
# HTML Table Renderer for DeepGit Lite
# ---------------------------
def format_percent(value):
try:
return f"{float(value) * 100:.1f}%"
except:
return value
def parse_result_to_html(raw_result: str) -> str:
entries = raw_result.strip().split("Final Rank:")
html = """
Rank
Title
Link
Semantic Similarity
Final Score
"""
for entry in entries[1:]:
lines = entry.strip().split("\n")
data = {}
data["Final Rank"] = lines[0].strip()
for line in lines[1:]:
if ": " in line:
key, val = line.split(": ", 1)
data[key.strip()] = val.strip()
html += f"""