aizerner commited on
Commit
88ec0a4
·
verified ·
1 Parent(s): 893d74d

Update llm.py

Browse files
Files changed (1) hide show
  1. llm.py +15 -16
llm.py CHANGED
@@ -3,6 +3,7 @@ import google.generativeai as genai
3
  from typing import Dict, Any
4
  from dotenv import load_dotenv
5
 
 
6
  load_dotenv()
7
 
8
  GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
@@ -11,19 +12,11 @@ if not GEMINI_API_KEY:
11
 
12
  # Set a working US proxy (test and replace; this one is from free lists as of Dec 2025)
13
  # Find fresh ones at free-proxy-list.net or proxylister.com — filter for US, HTTP, high uptime
14
- os.environ['HTTP_PROXY'] = 'http://172.93.187.26:80'
15
- os.environ['HTTPS_PROXY'] = 'http://172.93.187.26:80'
16
-
17
- # Configure Gemini ONCE at the top with proxy support
18
- try:
19
- genai.configure(
20
- api_key=GEMINI_API_KEY,
21
- transport='rest' # Required for proxies; switches to HTTP
22
- )
23
- print("Gemini configured with proxy successfully.") # Log for HF debugging
24
- except Exception as e:
25
- print(f"Gemini config error: {str(e)}") # Shows in HF logs if fails
26
 
 
 
27
  def build_prompt_from_counts(class_counts: Dict[str, int], sample_type: str = "Blood smear", stain: str = "Giemsa", magnification: str = "1000x") -> str:
28
  """
29
  Build a prompt for AI analysis based on detection results.
@@ -67,8 +60,15 @@ def analyze_detections(class_counts: Dict[str, int], sample_type: str = "Blood s
67
  Dictionary containing analysis results
68
  """
69
  try:
70
- # Initialize the Gemini model (no re-configure needed)
71
- model = genai.GenerativeModel('gemini-2.5-flash') # Updated to valid 2025 model
 
 
 
 
 
 
 
72
 
73
  # Build the prompt
74
  prompt = build_prompt_from_counts(class_counts, sample_type, stain, magnification)
@@ -83,9 +83,8 @@ def analyze_detections(class_counts: Dict[str, int], sample_type: str = "Blood s
83
  }
84
 
85
  except Exception as e:
86
- print(f"Gemini analysis error: {str(e)}") # Log for debugging in HF
87
  return {
88
  "success": False,
89
  "error": str(e),
90
  "detection_summary": class_counts
91
- }
 
3
  from typing import Dict, Any
4
  from dotenv import load_dotenv
5
 
6
+
7
  load_dotenv()
8
 
9
  GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
 
12
 
13
  # Set a working US proxy (test and replace; this one is from free lists as of Dec 2025)
14
  # Find fresh ones at free-proxy-list.net or proxylister.com — filter for US, HTTP, high uptime
15
+ os.environ['HTTP_PROXY'] = 'http://50.217.226.40:80'
16
+ os.environ['HTTPS_PROXY'] = 'http://50.217.226.40:80'
 
 
 
 
 
 
 
 
 
 
17
 
18
+ # Get API key from environment variable
19
+ # Check GC LOL -molt
20
  def build_prompt_from_counts(class_counts: Dict[str, int], sample_type: str = "Blood smear", stain: str = "Giemsa", magnification: str = "1000x") -> str:
21
  """
22
  Build a prompt for AI analysis based on detection results.
 
60
  Dictionary containing analysis results
61
  """
62
  try:
63
+ # Configure the API key
64
+ genai.configure(
65
+ api_key=GEMINI_API_KEY,
66
+ transport='rest' # Required for proxies; switches to HTTP
67
+ )
68
+ print("Gemini configured with proxy successfully.")
69
+
70
+ # Initialize the Gemini model
71
+ model = genai.GenerativeModel('gemini-2.0-flash')
72
 
73
  # Build the prompt
74
  prompt = build_prompt_from_counts(class_counts, sample_type, stain, magnification)
 
83
  }
84
 
85
  except Exception as e:
 
86
  return {
87
  "success": False,
88
  "error": str(e),
89
  "detection_summary": class_counts
90
+ }