Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
import google.generativeai as genai
|
| 3 |
import requests
|
| 4 |
import base64
|
|
|
|
| 5 |
|
| 6 |
def fetch_github_files(github_url, personal_access_token):
|
| 7 |
try:
|
|
@@ -29,7 +30,7 @@ def fetch_github_files(github_url, personal_access_token):
|
|
| 29 |
# Set up headers with the personal access token
|
| 30 |
headers = {
|
| 31 |
"Authorization": f"token {personal_access_token}",
|
| 32 |
-
"Accept": "application/vnd.github.v3
|
| 33 |
}
|
| 34 |
|
| 35 |
for file_path in dependency_files:
|
|
@@ -40,9 +41,14 @@ def fetch_github_files(github_url, personal_access_token):
|
|
| 40 |
response = requests.get(api_url, headers=headers)
|
| 41 |
|
| 42 |
if response.status_code == 200:
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
if not all_content:
|
| 48 |
return "Error: No dependency files found in the repository."
|
|
@@ -50,6 +56,8 @@ def fetch_github_files(github_url, personal_access_token):
|
|
| 50 |
return all_content
|
| 51 |
except requests.exceptions.RequestException as e:
|
| 52 |
return f"Error accessing GitHub: {str(e)}"
|
|
|
|
|
|
|
| 53 |
|
| 54 |
def process_with_gemini(file_content, gemini_api_key):
|
| 55 |
genai.configure(api_key=gemini_api_key)
|
|
|
|
| 2 |
import google.generativeai as genai
|
| 3 |
import requests
|
| 4 |
import base64
|
| 5 |
+
import json
|
| 6 |
|
| 7 |
def fetch_github_files(github_url, personal_access_token):
|
| 8 |
try:
|
|
|
|
| 30 |
# Set up headers with the personal access token
|
| 31 |
headers = {
|
| 32 |
"Authorization": f"token {personal_access_token}",
|
| 33 |
+
"Accept": "application/vnd.github.v3+json"
|
| 34 |
}
|
| 35 |
|
| 36 |
for file_path in dependency_files:
|
|
|
|
| 41 |
response = requests.get(api_url, headers=headers)
|
| 42 |
|
| 43 |
if response.status_code == 200:
|
| 44 |
+
content = response.json()
|
| 45 |
+
if isinstance(content, dict) and 'content' in content:
|
| 46 |
+
# This is a file
|
| 47 |
+
file_content = base64.b64decode(content['content']).decode('utf-8')
|
| 48 |
+
all_content += f"\n\n--- {file_path} ---\n{file_content}"
|
| 49 |
+
else:
|
| 50 |
+
# This is a directory or something else, skip it
|
| 51 |
+
continue
|
| 52 |
|
| 53 |
if not all_content:
|
| 54 |
return "Error: No dependency files found in the repository."
|
|
|
|
| 56 |
return all_content
|
| 57 |
except requests.exceptions.RequestException as e:
|
| 58 |
return f"Error accessing GitHub: {str(e)}"
|
| 59 |
+
except json.JSONDecodeError:
|
| 60 |
+
return f"Error: Unable to parse GitHub API response for {file_path}"
|
| 61 |
|
| 62 |
def process_with_gemini(file_content, gemini_api_key):
|
| 63 |
genai.configure(api_key=gemini_api_key)
|