Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- Dockerfile +53 -0
- app.py +106 -0
- docker-compose.yml +24 -0
- poetry.lock +0 -0
- pyproject.toml +35 -0
- requirements.txt +6 -0
Dockerfile
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12.3-slim as builder
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
# Install system dependencies required for building
|
| 6 |
+
RUN apt-get update && apt-get install -y \
|
| 7 |
+
protobuf-compiler \
|
| 8 |
+
gcc \
|
| 9 |
+
g++ \
|
| 10 |
+
cmake \
|
| 11 |
+
pkg-config \
|
| 12 |
+
build-essential \
|
| 13 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 14 |
+
|
| 15 |
+
# Install poetry
|
| 16 |
+
RUN pip install poetry
|
| 17 |
+
|
| 18 |
+
# Copy dependency files
|
| 19 |
+
COPY pyproject.toml poetry.lock ./
|
| 20 |
+
|
| 21 |
+
# Configure poetry and install dependencies
|
| 22 |
+
RUN poetry config virtualenvs.create false \
|
| 23 |
+
&& poetry install --no-interaction --no-ansi --no-root
|
| 24 |
+
|
| 25 |
+
# Second stage
|
| 26 |
+
FROM python:3.12.3-slim
|
| 27 |
+
|
| 28 |
+
WORKDIR /app
|
| 29 |
+
|
| 30 |
+
# Copy installed dependencies from builder
|
| 31 |
+
COPY --from=builder /usr/local/lib/python3.12/site-packages/ /usr/local/lib/python3.12/site-packages/
|
| 32 |
+
COPY --from=builder /usr/local/bin/ /usr/local/bin/
|
| 33 |
+
|
| 34 |
+
# Install runtime system dependencies
|
| 35 |
+
RUN apt-get update && apt-get install -y \
|
| 36 |
+
protobuf-compiler \
|
| 37 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 38 |
+
|
| 39 |
+
# Copy application code
|
| 40 |
+
COPY . .
|
| 41 |
+
|
| 42 |
+
# Create non-root user
|
| 43 |
+
RUN useradd -m appuser && \
|
| 44 |
+
chown -R appuser:appuser /app
|
| 45 |
+
USER appuser
|
| 46 |
+
|
| 47 |
+
EXPOSE 7860
|
| 48 |
+
|
| 49 |
+
# Health check
|
| 50 |
+
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
| 51 |
+
CMD curl -f http://localhost:7860/ || exit 1
|
| 52 |
+
|
| 53 |
+
CMD ["poetry", "run", "python", "app.py"]
|
app.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,
|
| 11 |
+
main_cat: str,
|
| 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 |
+
response = error_handler.handle_github_url_error(
|
| 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)
|
| 25 |
+
|
| 26 |
+
if not response.success:
|
| 27 |
+
return response.errors[0].message, "", ""
|
| 28 |
+
|
| 29 |
+
readme_topics = " ".join([
|
| 30 |
+
f"#{topic['topic'].lower()} ({topic['score']:.2f})"
|
| 31 |
+
for topic in response.data["readme_topics"]
|
| 32 |
+
])
|
| 33 |
+
|
| 34 |
+
code_topics = " ".join([
|
| 35 |
+
f"#{topic['topic'].lower()} ({topic['score']:.2f})"
|
| 36 |
+
for topic in response.data["code_topics"]
|
| 37 |
+
])
|
| 38 |
+
|
| 39 |
+
dependencies = " ".join([
|
| 40 |
+
f"#{dep.lower()}"
|
| 41 |
+
for dep in response.data["dependencies"]
|
| 42 |
+
])
|
| 43 |
+
|
| 44 |
+
return readme_topics, code_topics, dependencies
|
| 45 |
+
|
| 46 |
+
except Exception as e:
|
| 47 |
+
response = error_handler.handle_topic_analysis_error(str(e))
|
| 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 |
+
|
| 54 |
+
with gr.Row():
|
| 55 |
+
url_input = gr.Textbox(
|
| 56 |
+
label="GitHub URL",
|
| 57 |
+
placeholder="Enter GitHub repository URL"
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
with gr.Row():
|
| 61 |
+
main_category = gr.Dropdown(
|
| 62 |
+
choices=[None] + list(TOPIC_LIST.keys()),
|
| 63 |
+
label="Main Category",
|
| 64 |
+
value=None
|
| 65 |
+
)
|
| 66 |
+
sub_category = gr.Dropdown(
|
| 67 |
+
choices=[],
|
| 68 |
+
label="Sub Category"
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
with gr.Row():
|
| 72 |
+
use_gpu = gr.Checkbox(
|
| 73 |
+
label="Use GPU (Check if you have CUDA-capable GPU)",
|
| 74 |
+
value=False
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
with gr.Row():
|
| 78 |
+
generate_btn = gr.Button("Generate Topics")
|
| 79 |
+
|
| 80 |
+
with gr.Row():
|
| 81 |
+
readme_topics = gr.Textbox(label="README Topics")
|
| 82 |
+
code_topics = gr.Textbox(label="Code Analysis Topics")
|
| 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 |
+
)
|
| 89 |
+
|
| 90 |
+
main_category.change(
|
| 91 |
+
update_sub_category,
|
| 92 |
+
inputs=main_category,
|
| 93 |
+
outputs=sub_category
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
generate_btn.click(
|
| 97 |
+
process_url,
|
| 98 |
+
inputs=[url_input, main_category, sub_category, use_gpu],
|
| 99 |
+
outputs=[readme_topics, code_topics, dependencies]
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
return demo
|
| 103 |
+
|
| 104 |
+
if __name__ == "__main__":
|
| 105 |
+
demo = create_interface()
|
| 106 |
+
demo.launch(share=True)
|
docker-compose.yml
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
web:
|
| 5 |
+
build: .
|
| 6 |
+
ports:
|
| 7 |
+
- "7860:7860"
|
| 8 |
+
environment:
|
| 9 |
+
- GRADIO_SERVER_NAME=0.0.0.0
|
| 10 |
+
- GRADIO_SERVER_PORT=7860
|
| 11 |
+
deploy:
|
| 12 |
+
resources:
|
| 13 |
+
limits:
|
| 14 |
+
memory: 4G
|
| 15 |
+
healthcheck:
|
| 16 |
+
test: ["CMD", "curl", "-f", "http://localhost:7860/"]
|
| 17 |
+
interval: 30s
|
| 18 |
+
timeout: 30s
|
| 19 |
+
retries: 3
|
| 20 |
+
logging:
|
| 21 |
+
driver: "json-file"
|
| 22 |
+
options:
|
| 23 |
+
max-size: "10m"
|
| 24 |
+
max-file: "3"
|
poetry.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
pyproject.toml
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[tool.poetry]
|
| 2 |
+
name = "github-topic-generator"
|
| 3 |
+
version = "0.1.2"
|
| 4 |
+
description = "GitHub repository topic generator using AI"
|
| 5 |
+
authors = ["Namgyu-Youn <[email protected]>"]
|
| 6 |
+
license = "MIT"
|
| 7 |
+
readme = "README.md"
|
| 8 |
+
package-mode = false
|
| 9 |
+
|
| 10 |
+
[tool.poetry.dependencies]
|
| 11 |
+
python = ">=3.10,<3.13"
|
| 12 |
+
gradio = "^5.9.1"
|
| 13 |
+
torch = {version = "^2.5.1", source = "pytorch"}
|
| 14 |
+
transformers = "^4.47.1"
|
| 15 |
+
aiohttp = "^3.11.11"
|
| 16 |
+
python-dotenv = "^1.0.1"
|
| 17 |
+
ruff = "^0.8.5"
|
| 18 |
+
tiktoken = "^0.5.2"
|
| 19 |
+
protobuf = "^4.25.3"
|
| 20 |
+
sentencepiece = "^0.1.99"
|
| 21 |
+
tokenizers = ">=0.21,<0.22"
|
| 22 |
+
|
| 23 |
+
[tool.poetry.group.dev.dependencies]
|
| 24 |
+
pytest = "^7.4.0"
|
| 25 |
+
pytest-cov = "^4.1.0"
|
| 26 |
+
pytest-asyncio = "^0.21.0"
|
| 27 |
+
|
| 28 |
+
[[tool.poetry.source]]
|
| 29 |
+
name = "pytorch"
|
| 30 |
+
url = "https://download.pytorch.org/whl/cpu"
|
| 31 |
+
priority = "explicit"
|
| 32 |
+
|
| 33 |
+
[build-system]
|
| 34 |
+
requires = ["poetry-core>=1.0.0"]
|
| 35 |
+
build-backend = "poetry.core.masonry.api"
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy
|
| 2 |
+
torch
|
| 3 |
+
transformers
|
| 4 |
+
gradio
|
| 5 |
+
aiohttp
|
| 6 |
+
python-dotenv
|