bluenevus commited on
Commit
50ee921
·
verified ·
1 Parent(s): db43f4f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -3,6 +3,7 @@ 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:
@@ -59,10 +60,16 @@ def fetch_github_files(github_url, personal_access_token):
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)
64
  model = genai.GenerativeModel('gemini-2.5-pro-preview-03-25')
65
 
 
 
 
 
 
66
  prompt = f"""
67
  Analyze the following file content for open-source license information:
68
 
@@ -76,8 +83,12 @@ def process_with_gemini(file_content, gemini_api_key):
76
  5. Provide no other information such as greeting or summary as the purpose is to catalog and document all open source licenses used.
77
  """
78
 
79
- response = model.generate_content(prompt)
80
- return response.text
 
 
 
 
81
 
82
  def process_input(github_url, personal_access_token, gemini_api_key):
83
  if not github_url.startswith("https://github.com/"):
 
3
  import requests
4
  import base64
5
  import json
6
+ from tenacity import retry, stop_after_attempt, wait_exponential
7
 
8
  def fetch_github_files(github_url, personal_access_token):
9
  try:
 
60
  except json.JSONDecodeError:
61
  return f"Error: Unable to parse GitHub API response for {file_path}"
62
 
63
+ @retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
64
  def process_with_gemini(file_content, gemini_api_key):
65
  genai.configure(api_key=gemini_api_key)
66
  model = genai.GenerativeModel('gemini-2.5-pro-preview-03-25')
67
 
68
+ # Limit content size (adjust the limit as needed)
69
+ max_content_length = 10000 # characters
70
+ if len(file_content) > max_content_length:
71
+ file_content = file_content[:max_content_length] + "..."
72
+
73
  prompt = f"""
74
  Analyze the following file content for open-source license information:
75
 
 
83
  5. Provide no other information such as greeting or summary as the purpose is to catalog and document all open source licenses used.
84
  """
85
 
86
+ try:
87
+ response = model.generate_content(prompt, timeout=60) # Set a timeout of 60 seconds
88
+ return response.text
89
+ except Exception as e:
90
+ print(f"Error in Gemini API call: {str(e)}")
91
+ raise # This will trigger a retry
92
 
93
  def process_input(github_url, personal_access_token, gemini_api_key):
94
  if not github_url.startswith("https://github.com/"):