Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,82 +1,81 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from github_client import GitHubClient
|
| 3 |
-
from models import SearchRequest, SearchResponse
|
| 4 |
-
import os
|
| 5 |
-
from typing import Optional, Dict, Any, List
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def search_pr_opportunities(
|
| 9 |
-
keyword: Optional[str] = None,
|
| 10 |
-
topic: Optional[str] = None,
|
| 11 |
-
per_page: int = 5,
|
| 12 |
-
page: int = 1,
|
| 13 |
-
token: Optional[str] = None
|
| 14 |
-
) -> Dict[str, Any]:
|
| 15 |
-
"""Search GitHub for PR opportunities.
|
| 16 |
-
|
| 17 |
-
Args:
|
| 18 |
-
keyword: Keyword to search in repositories (optional)
|
| 19 |
-
topic: Topic to filter repositories (optional)
|
| 20 |
-
per_page: Number of results per page (default: 5)
|
| 21 |
-
page: Page number (default: 1)
|
| 22 |
-
token: GitHub token for authentication
|
| 23 |
-
|
| 24 |
-
Returns:
|
| 25 |
-
A dictionary containing opportunities and total count
|
| 26 |
-
"""
|
| 27 |
-
if not token:
|
| 28 |
-
token = os.getenv("GITHUB_TOKEN")
|
| 29 |
-
if not token:
|
| 30 |
-
raise gr.Error("GitHub token required in Authorization header or .env")
|
| 31 |
-
|
| 32 |
-
try:
|
| 33 |
-
client: GitHubClient = GitHubClient(token)
|
| 34 |
-
opportunities, total_count = client.find_pr_opportunities(
|
| 35 |
-
keyword=keyword,
|
| 36 |
-
topic=topic,
|
| 37 |
-
per_page=per_page,
|
| 38 |
-
page=page
|
| 39 |
-
)
|
| 40 |
-
|
| 41 |
-
# The return structure matches a dictionary format, so we type it as Dict[str, Any]
|
| 42 |
-
response: Dict[str, Any] = {
|
| 43 |
-
"opportunities": [
|
| 44 |
-
{
|
| 45 |
-
"repo_name": opp.repo_name,
|
| 46 |
-
"repo_url": opp.repo_url,
|
| 47 |
-
"issue_title": opp.issue_title,
|
| 48 |
-
"issue_url": opp.issue_url,
|
| 49 |
-
"issue_labels": opp.issue_labels,
|
| 50 |
-
"issue_body": opp.issue_body
|
| 51 |
-
} for opp in opportunities
|
| 52 |
-
],
|
| 53 |
-
"total_count": total_count
|
| 54 |
-
}
|
| 55 |
-
return response
|
| 56 |
-
except Exception as e:
|
| 57 |
-
raise gr.Error(str(e))
|
| 58 |
-
|
| 59 |
-
# Create the Gradio interface
|
| 60 |
-
demo: gr.Interface = gr.Interface(
|
| 61 |
-
fn=search_pr_opportunities,
|
| 62 |
-
inputs=[
|
| 63 |
-
gr.Textbox(label="Keyword", placeholder="e.g., fastapi"),
|
| 64 |
-
gr.Textbox(label="Topic", placeholder="e.g., python"),
|
| 65 |
-
gr.Slider(minimum=1, maximum=20, value=5, step=1, label="Results per page"),
|
| 66 |
-
gr.Slider(minimum=1, maximum=10, value=1, step=1, label="Page number")
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
["
|
| 74 |
-
["
|
| 75 |
-
["
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
if __name__ == "__main__":
|
| 82 |
demo.launch(mcp_server=True)
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from github_client import GitHubClient
|
| 3 |
+
from models import SearchRequest, SearchResponse
|
| 4 |
+
import os
|
| 5 |
+
from typing import Optional, Dict, Any, List
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def search_pr_opportunities(
|
| 9 |
+
keyword: Optional[str] = None,
|
| 10 |
+
topic: Optional[str] = None,
|
| 11 |
+
per_page: int = 5,
|
| 12 |
+
page: int = 1,
|
| 13 |
+
token: Optional[str] = None
|
| 14 |
+
) -> Dict[str, Any]:
|
| 15 |
+
"""Search GitHub for PR opportunities.
|
| 16 |
+
|
| 17 |
+
Args:
|
| 18 |
+
keyword: Keyword to search in repositories (optional)
|
| 19 |
+
topic: Topic to filter repositories (optional)
|
| 20 |
+
per_page: Number of results per page (default: 5)
|
| 21 |
+
page: Page number (default: 1)
|
| 22 |
+
token: GitHub token for authentication
|
| 23 |
+
|
| 24 |
+
Returns:
|
| 25 |
+
A dictionary containing opportunities and total count
|
| 26 |
+
"""
|
| 27 |
+
if not token:
|
| 28 |
+
token = os.getenv("GITHUB_TOKEN")
|
| 29 |
+
if not token:
|
| 30 |
+
raise gr.Error("GitHub token required in Authorization header or .env")
|
| 31 |
+
|
| 32 |
+
try:
|
| 33 |
+
client: GitHubClient = GitHubClient(token)
|
| 34 |
+
opportunities, total_count = client.find_pr_opportunities(
|
| 35 |
+
keyword=keyword,
|
| 36 |
+
topic=topic,
|
| 37 |
+
per_page=per_page,
|
| 38 |
+
page=page
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
# The return structure matches a dictionary format, so we type it as Dict[str, Any]
|
| 42 |
+
response: Dict[str, Any] = {
|
| 43 |
+
"opportunities": [
|
| 44 |
+
{
|
| 45 |
+
"repo_name": opp.repo_name,
|
| 46 |
+
"repo_url": opp.repo_url,
|
| 47 |
+
"issue_title": opp.issue_title,
|
| 48 |
+
"issue_url": opp.issue_url,
|
| 49 |
+
"issue_labels": opp.issue_labels,
|
| 50 |
+
"issue_body": opp.issue_body
|
| 51 |
+
} for opp in opportunities
|
| 52 |
+
],
|
| 53 |
+
"total_count": total_count
|
| 54 |
+
}
|
| 55 |
+
return response
|
| 56 |
+
except Exception as e:
|
| 57 |
+
raise gr.Error(str(e))
|
| 58 |
+
|
| 59 |
+
# Create the Gradio interface
|
| 60 |
+
demo: gr.Interface = gr.Interface(
|
| 61 |
+
fn=search_pr_opportunities,
|
| 62 |
+
inputs=[
|
| 63 |
+
gr.Textbox(label="Keyword", placeholder="e.g., fastapi"),
|
| 64 |
+
gr.Textbox(label="Topic", placeholder="e.g., python"),
|
| 65 |
+
gr.Slider(minimum=1, maximum=20, value=5, step=1, label="Results per page"),
|
| 66 |
+
gr.Slider(minimum=1, maximum=10, value=1, step=1, label="Page number")
|
| 67 |
+
],
|
| 68 |
+
outputs=gr.JSON(label="Search Results"),
|
| 69 |
+
title="GitHub PR Opportunity Finder",
|
| 70 |
+
description="Search GitHub repositories for PR opportunities (issues labeled 'good first issue' or 'help wanted')",
|
| 71 |
+
examples=[
|
| 72 |
+
["fastapi", "python", 5, 1, ""],
|
| 73 |
+
["react", "javascript", 3, 1, ""],
|
| 74 |
+
["machine-learning", None, 2, 1, ""],
|
| 75 |
+
[None, "web-development", 4, 1, ""]
|
| 76 |
+
]
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
# Launch with MCP server enabled
|
| 80 |
+
if __name__ == "__main__":
|
|
|
|
| 81 |
demo.launch(mcp_server=True)
|