NeerajCodz commited on
Commit
12fdaf8
·
1 Parent(s): 18bafbe

Fix: Switch to google-generativeai and upgrade Gradio to v5.10+ to resolve dependency conflicts

Browse files
Files changed (2) hide show
  1. app.py +7 -14
  2. requirements.txt +2 -3
app.py CHANGED
@@ -6,7 +6,7 @@ import pickle
6
  import numpy as np
7
  import re
8
  import os
9
- from google import genai
10
  from pathlib import Path
11
  from typing import Dict, Tuple
12
  from nltk.corpus import stopwords
@@ -20,11 +20,10 @@ load_dotenv()
20
  # Configure Gemini
21
  GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
22
  if GEMINI_API_KEY:
23
- client = genai.Client(api_key=GEMINI_API_KEY)
24
- model_name = 'gemini-1.5-flash'
25
  else:
26
- client = None
27
- model_name = None
28
  print("WARNING: GEMINI_API_KEY not found in environment variables")
29
 
30
  # Download NLTK data if not present
@@ -134,7 +133,7 @@ def extract_features(question: str) -> np.ndarray:
134
 
135
  def get_gemini_solution(question: str, image_path: str = None) -> str:
136
  """Get solution from Gemini API"""
137
- if not client or not model_name:
138
  return "Gemini API key not configured. Please set GEMINI_API_KEY in your .env file."
139
 
140
  try:
@@ -144,17 +143,11 @@ def get_gemini_solution(question: str, image_path: str = None) -> str:
144
  img = Image.open(image_path)
145
  prompt = "Solve this math problem step-by-step with clear explanations."
146
 
147
- response = client.models.generate_content(
148
- model=model_name,
149
- contents=[prompt, img]
150
- )
151
  else:
152
  prompt = f"Solve this math problem step-by-step: {question}"
153
 
154
- response = client.models.generate_content(
155
- model=model_name,
156
- contents=prompt
157
- )
158
 
159
  return response.text
160
  except Exception as e:
 
6
  import numpy as np
7
  import re
8
  import os
9
+ import google.generativeai as genai
10
  from pathlib import Path
11
  from typing import Dict, Tuple
12
  from nltk.corpus import stopwords
 
20
  # Configure Gemini
21
  GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
22
  if GEMINI_API_KEY:
23
+ genai.configure(api_key=GEMINI_API_KEY)
24
+ gemini_model = genai.GenerativeModel('gemini-1.5-flash')
25
  else:
26
+ gemini_model = None
 
27
  print("WARNING: GEMINI_API_KEY not found in environment variables")
28
 
29
  # Download NLTK data if not present
 
133
 
134
  def get_gemini_solution(question: str, image_path: str = None) -> str:
135
  """Get solution from Gemini API"""
136
+ if not gemini_model:
137
  return "Gemini API key not configured. Please set GEMINI_API_KEY in your .env file."
138
 
139
  try:
 
143
  img = Image.open(image_path)
144
  prompt = "Solve this math problem step-by-step with clear explanations."
145
 
146
+ response = gemini_model.generate_content([prompt, img])
 
 
 
147
  else:
148
  prompt = f"Solve this math problem step-by-step: {question}"
149
 
150
+ response = gemini_model.generate_content(prompt)
 
 
 
151
 
152
  return response.text
153
  except Exception as e:
requirements.txt CHANGED
@@ -1,12 +1,11 @@
1
- gradio==4.44.1
2
- huggingface_hub==0.24.7
3
  numpy>=1.26.0
4
  pandas>=2.1.0
5
  scikit-learn>=1.4.0
6
  scipy>=1.11.0
7
  nltk
8
  python-dotenv
9
- google-genai
10
  Pillow
11
  fastparquet
12
  pyarrow
 
1
+ gradio>=5.10.0
2
+ google-generativeai
3
  numpy>=1.26.0
4
  pandas>=2.1.0
5
  scikit-learn>=1.4.0
6
  scipy>=1.11.0
7
  nltk
8
  python-dotenv
 
9
  Pillow
10
  fastparquet
11
  pyarrow