lakkiroy commited on
Commit
e68d892
Β·
1 Parent(s): 1528f0c

Sync with local repository - 2025-08-12 08:12:32

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +20 -22
README.md CHANGED
@@ -79,4 +79,4 @@ This project is licensed under the MIT License.
79
 
80
  ---
81
 
82
- **Note**: This application processes public repositories only. Private repositories require authentication tokens.
 
79
 
80
  ---
81
 
82
+ **Note**: This application processes public repositories only. Private repositories require authentication tokens.
app.py CHANGED
@@ -49,14 +49,16 @@ def validate_github_url(url: str) -> bool:
49
  async def process_repository(repo_url: str, branch: str = "main") -> tuple:
50
  """Process a GitHub repository and return status"""
51
  if not validate_github_url(repo_url):
52
- return "❌ Error", "Invalid GitHub URL. Please provide a valid GitHub repository URL."
 
53
 
54
  try:
55
  repo_id = github_service.generate_repo_id(repo_url)
56
 
57
  # Check if already processed
58
  if repo_id in repo_data:
59
- return "βœ… Ready", f"Repository already processed! You can now ask questions about the code."
 
60
 
61
  # Clone repository
62
  yield "πŸ”„ Processing", "Cloning repository..."
@@ -68,7 +70,8 @@ async def process_repository(repo_url: str, branch: str = "main") -> tuple:
68
 
69
  if not files:
70
  github_service.cleanup_repo(repo_path)
71
- return "❌ Error", "No supported files found in the repository."
 
72
 
73
  # Create embeddings
74
  yield "πŸ”„ Processing", f"Creating embeddings for {len(files)} files (this may take a while)..."
@@ -88,30 +91,25 @@ async def process_repository(repo_url: str, branch: str = "main") -> tuple:
88
  yield "βœ… Ready", f"Repository processed successfully! Found {len(files)} files. You can now ask questions about the code."
89
 
90
  except Exception as e:
91
- return "❌ Error", f"Error processing repository: {str(e)}"
 
92
 
93
  def process_repo_sync(repo_url: str, branch: str = "main"):
94
- """Synchronous wrapper for repository processing"""
 
 
95
  try:
96
- # Run the async function
97
- loop = asyncio.new_event_loop()
98
- asyncio.set_event_loop(loop)
99
-
100
- async def run_process():
101
- async for status, message in process_repository(repo_url, branch):
102
  yield status, message
103
-
104
- # Get the final result
105
- gen = run_process()
106
- result = None
107
- async for result in gen:
108
- pass
109
-
110
- loop.close()
111
- return result if result else ("❌ Error", "Processing failed")
112
-
113
  except Exception as e:
114
- return "❌ Error", f"Error: {str(e)}"
 
 
115
 
116
  async def chat_with_repository(message: str, repo_url: str, history: List) -> tuple:
117
  """Chat with the processed repository"""
 
49
  async def process_repository(repo_url: str, branch: str = "main") -> tuple:
50
  """Process a GitHub repository and return status"""
51
  if not validate_github_url(repo_url):
52
+ yield "❌ Error", "Invalid GitHub URL. Please provide a valid GitHub repository URL."
53
+ return
54
 
55
  try:
56
  repo_id = github_service.generate_repo_id(repo_url)
57
 
58
  # Check if already processed
59
  if repo_id in repo_data:
60
+ yield "βœ… Ready", f"Repository already processed! You can now ask questions about the code."
61
+ return
62
 
63
  # Clone repository
64
  yield "πŸ”„ Processing", "Cloning repository..."
 
70
 
71
  if not files:
72
  github_service.cleanup_repo(repo_path)
73
+ yield "❌ Error", "No supported files found in the repository."
74
+ return
75
 
76
  # Create embeddings
77
  yield "πŸ”„ Processing", f"Creating embeddings for {len(files)} files (this may take a while)..."
 
91
  yield "βœ… Ready", f"Repository processed successfully! Found {len(files)} files. You can now ask questions about the code."
92
 
93
  except Exception as e:
94
+ yield "❌ Error", f"Error processing repository: {str(e)}"
95
+ return
96
 
97
  def process_repo_sync(repo_url: str, branch: str = "main"):
98
+ """Synchronous wrapper for repository processing that streams updates to Gradio."""
99
+ loop = asyncio.new_event_loop()
100
+ asyncio.set_event_loop(loop)
101
  try:
102
+ agen = process_repository(repo_url, branch)
103
+ while True:
104
+ try:
105
+ status, message = loop.run_until_complete(agen.__anext__())
 
 
106
  yield status, message
107
+ except StopAsyncIteration:
108
+ break
 
 
 
 
 
 
 
 
109
  except Exception as e:
110
+ yield "❌ Error", f"Error: {str(e)}"
111
+ finally:
112
+ loop.close()
113
 
114
  async def chat_with_repository(message: str, repo_url: str, history: List) -> tuple:
115
  """Chat with the processed repository"""