Update app.py
Browse files
app.py
CHANGED
|
@@ -6,11 +6,11 @@ import io
|
|
| 6 |
def fetch_github_file(github_url, ssh_private_key):
|
| 7 |
try:
|
| 8 |
# Parse the GitHub URL
|
| 9 |
-
parts = github_url.split('/')
|
| 10 |
-
owner = parts[
|
| 11 |
-
repo = parts[
|
| 12 |
-
branch =
|
| 13 |
-
file_path = '
|
| 14 |
|
| 15 |
# Set up SSH client
|
| 16 |
ssh = paramiko.SSHClient()
|
|
@@ -35,26 +35,24 @@ def fetch_github_file(github_url, ssh_private_key):
|
|
| 35 |
ssh.close()
|
| 36 |
|
| 37 |
if not file_content:
|
| 38 |
-
return
|
| 39 |
|
| 40 |
-
return
|
| 41 |
except paramiko.AuthenticationException:
|
| 42 |
-
return
|
| 43 |
except paramiko.SSHException as ssh_err:
|
| 44 |
-
return
|
| 45 |
except Exception as e:
|
| 46 |
-
return
|
| 47 |
|
| 48 |
def process_with_gemini(file_content, gemini_api_key):
|
| 49 |
genai.configure(api_key=gemini_api_key)
|
| 50 |
model = genai.GenerativeModel('gemini-2.5-pro-preview-03-25')
|
| 51 |
|
| 52 |
-
combined_content = "\n\n".join([f"File: {name}\n{content}" for name, content in file_content.items()])
|
| 53 |
-
|
| 54 |
prompt = f"""
|
| 55 |
Analyze the following file content for open-source license information:
|
| 56 |
|
| 57 |
-
{
|
| 58 |
|
| 59 |
Please provide:
|
| 60 |
1. A list of dependencies and their versions
|
|
@@ -72,15 +70,15 @@ def process_input(file, github_url, ssh_private_key, gemini_api_key):
|
|
| 72 |
return "Error: Please either upload a file OR provide a GitHub URL, not both."
|
| 73 |
|
| 74 |
if file is not None:
|
| 75 |
-
file_content =
|
| 76 |
elif github_url and ssh_private_key:
|
| 77 |
-
if not github_url.startswith("
|
| 78 |
-
return "Error: Invalid GitHub URL. Please use the format:
|
| 79 |
if not ssh_private_key.strip():
|
| 80 |
return "Error: SSH Private Key is empty. Please provide a valid key."
|
| 81 |
file_content = fetch_github_file(github_url, ssh_private_key)
|
| 82 |
-
if
|
| 83 |
-
return file_content
|
| 84 |
else:
|
| 85 |
return "Error: Please either upload a file OR provide both GitHub URL and SSH Private Key."
|
| 86 |
|
|
|
|
| 6 |
def fetch_github_file(github_url, ssh_private_key):
|
| 7 |
try:
|
| 8 |
# Parse the GitHub URL
|
| 9 |
+
parts = github_url.split(':')[1].split('/')
|
| 10 |
+
owner = parts[0]
|
| 11 |
+
repo = parts[1].split('.git')[0]
|
| 12 |
+
branch = 'main' # You might want to make this configurable
|
| 13 |
+
file_path = '' # You might want to make this configurable
|
| 14 |
|
| 15 |
# Set up SSH client
|
| 16 |
ssh = paramiko.SSHClient()
|
|
|
|
| 35 |
ssh.close()
|
| 36 |
|
| 37 |
if not file_content:
|
| 38 |
+
return "Error: File not found or empty."
|
| 39 |
|
| 40 |
+
return file_content
|
| 41 |
except paramiko.AuthenticationException:
|
| 42 |
+
return "Error: Authentication failed. Please check your SSH key."
|
| 43 |
except paramiko.SSHException as ssh_err:
|
| 44 |
+
return f"SSH Error: {str(ssh_err)}"
|
| 45 |
except Exception as e:
|
| 46 |
+
return f"Error accessing GitHub: {str(e)}"
|
| 47 |
|
| 48 |
def process_with_gemini(file_content, gemini_api_key):
|
| 49 |
genai.configure(api_key=gemini_api_key)
|
| 50 |
model = genai.GenerativeModel('gemini-2.5-pro-preview-03-25')
|
| 51 |
|
|
|
|
|
|
|
| 52 |
prompt = f"""
|
| 53 |
Analyze the following file content for open-source license information:
|
| 54 |
|
| 55 |
+
{file_content}
|
| 56 |
|
| 57 |
Please provide:
|
| 58 |
1. A list of dependencies and their versions
|
|
|
|
| 70 |
return "Error: Please either upload a file OR provide a GitHub URL, not both."
|
| 71 |
|
| 72 |
if file is not None:
|
| 73 |
+
file_content = file.decode('utf-8')
|
| 74 |
elif github_url and ssh_private_key:
|
| 75 |
+
if not github_url.startswith("git@github.com:"):
|
| 76 |
+
return "Error: Invalid GitHub URL. Please use the format: git@github.com:username/repository.git"
|
| 77 |
if not ssh_private_key.strip():
|
| 78 |
return "Error: SSH Private Key is empty. Please provide a valid key."
|
| 79 |
file_content = fetch_github_file(github_url, ssh_private_key)
|
| 80 |
+
if file_content.startswith("Error:"):
|
| 81 |
+
return file_content
|
| 82 |
else:
|
| 83 |
return "Error: Please either upload a file OR provide both GitHub URL and SSH Private Key."
|
| 84 |
|