faizee07 commited on
Commit
7714423
Β·
verified Β·
1 Parent(s): ad30a06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -5,10 +5,9 @@ from flask import Flask, request, jsonify, render_template_string
5
  import git
6
  import json
7
  import google.generativeai as genai
8
- import traceback # Import traceback for detailed error logging
9
 
10
  # --- Configure API Key ---
11
- # This block is essential for checking if the key is loaded.
12
  API_KEY = os.environ.get("GOOGLE_API_KEY")
13
  if API_KEY:
14
  try:
@@ -19,10 +18,8 @@ if API_KEY:
19
  else:
20
  print("🚨 WARNING: GOOGLE_API_KEY secret not set in Hugging Face Spaces.")
21
 
22
- # Create the Flask app instance
23
  app = Flask(__name__)
24
 
25
- # The HTML template remains the same
26
  HTML_TEMPLATE = """
27
  <!DOCTYPE html>
28
  <html lang="en">
@@ -122,14 +119,15 @@ def generate_readme_with_llm(repo_path):
122
 
123
  try:
124
  print("Step 5: Sending request to Gemini API...")
125
- model = genai.GenerativeModel('gemini-1.5-flash-latest')
 
 
126
  response = model.generate_content(prompt)
127
  print("Step 6: Received response from Gemini API.")
128
  readme_text = response.text.strip().replace("```markdown", "").replace("```", "")
129
  return readme_text
130
  except Exception as e:
131
  print(f"🚨🚨🚨 CRITICAL ERROR during Gemini API call: {e}")
132
- # Re-raise the exception to be caught by the main handler
133
  raise
134
 
135
  @app.route('/')
@@ -166,9 +164,8 @@ def generate():
166
  return jsonify({"readme": readme_content})
167
 
168
  except Exception as e:
169
- # This will now print the true error to your logs
170
  print(f"🚨🚨🚨 AN UNEXPECTED ERROR OCCURRED in /generate route 🚨🚨🚨")
171
- traceback.print_exc() # Print the full traceback for detailed debugging
172
  return jsonify({"error": "An unexpected server error occurred. Please check the logs."}), 500
173
  finally:
174
  print(f"Step 8: Cleaning up temporary directory: {temp_dir}")
 
5
  import git
6
  import json
7
  import google.generativeai as genai
8
+ import traceback
9
 
10
  # --- Configure API Key ---
 
11
  API_KEY = os.environ.get("GOOGLE_API_KEY")
12
  if API_KEY:
13
  try:
 
18
  else:
19
  print("🚨 WARNING: GOOGLE_API_KEY secret not set in Hugging Face Spaces.")
20
 
 
21
  app = Flask(__name__)
22
 
 
23
  HTML_TEMPLATE = """
24
  <!DOCTYPE html>
25
  <html lang="en">
 
119
 
120
  try:
121
  print("Step 5: Sending request to Gemini API...")
122
+ # --- BUG FIX: Corrected the model name ---
123
+ model = genai.GenerativeModel('gemini-1.5-flash')
124
+
125
  response = model.generate_content(prompt)
126
  print("Step 6: Received response from Gemini API.")
127
  readme_text = response.text.strip().replace("```markdown", "").replace("```", "")
128
  return readme_text
129
  except Exception as e:
130
  print(f"🚨🚨🚨 CRITICAL ERROR during Gemini API call: {e}")
 
131
  raise
132
 
133
  @app.route('/')
 
164
  return jsonify({"readme": readme_content})
165
 
166
  except Exception as e:
 
167
  print(f"🚨🚨🚨 AN UNEXPECTED ERROR OCCURRED in /generate route 🚨🚨🚨")
168
+ traceback.print_exc()
169
  return jsonify({"error": "An unexpected server error occurred. Please check the logs."}), 500
170
  finally:
171
  print(f"Step 8: Cleaning up temporary directory: {temp_dir}")