Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,9 +3,9 @@ from transformers import AutoImageProcessor, AutoModelForImageClassification
|
|
3 |
from PIL import Image
|
4 |
import torch
|
5 |
import numpy as np
|
6 |
-
import json
|
7 |
import logging
|
8 |
import requests
|
|
|
9 |
|
10 |
# Configure Logging
|
11 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
@@ -21,26 +21,27 @@ except Exception as e:
|
|
21 |
raise RuntimeError("Failed to load the model. Please check the logs for details.")
|
22 |
|
23 |
# Gemini API Key (Replace with your actual key)
|
24 |
-
GEMINI_API_KEY = "AIzaSyCiRL0ES-zsJGJYsY03xmpwqcggDGcL2Fk"
|
25 |
|
26 |
# Function to Get AI-Powered Treatment Suggestions
|
27 |
def get_treatment_suggestions(disease_name):
|
28 |
url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateText?key={GEMINI_API_KEY}"
|
29 |
headers = {"Content-Type": "application/json"}
|
30 |
data = {
|
31 |
-
"prompt": f"Provide detailed organic and chemical treatment options, including dosage and preventive care, for {disease_name} in crops.",
|
32 |
"temperature": 0.7,
|
33 |
-
"
|
34 |
}
|
35 |
-
|
36 |
try:
|
37 |
response = requests.post(url, headers=headers, json=data)
|
38 |
if response.status_code == 200:
|
39 |
result = response.json()
|
40 |
-
treatment = result.get("candidates", [{}])[0].get("
|
41 |
return treatment
|
42 |
else:
|
43 |
-
|
|
|
44 |
except Exception as e:
|
45 |
logging.error(f"Error fetching treatment suggestions: {str(e)}")
|
46 |
return "Error retrieving treatment details."
|
|
|
3 |
from PIL import Image
|
4 |
import torch
|
5 |
import numpy as np
|
|
|
6 |
import logging
|
7 |
import requests
|
8 |
+
import os
|
9 |
|
10 |
# Configure Logging
|
11 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
|
|
21 |
raise RuntimeError("Failed to load the model. Please check the logs for details.")
|
22 |
|
23 |
# Gemini API Key (Replace with your actual key)
|
24 |
+
GEMINI_API_KEY = os.getenv("AIzaSyCiRL0ES-zsJGJYsY03xmpwqcggDGcL2Fk", "AIzaSyCiRL0ES-zsJGJYsY03xmpwqcggDGcL2Fk")
|
25 |
|
26 |
# Function to Get AI-Powered Treatment Suggestions
|
27 |
def get_treatment_suggestions(disease_name):
|
28 |
url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateText?key={GEMINI_API_KEY}"
|
29 |
headers = {"Content-Type": "application/json"}
|
30 |
data = {
|
31 |
+
"prompt": { "text": f"Provide detailed organic and chemical treatment options, including dosage and preventive care, for {disease_name} in crops." },
|
32 |
"temperature": 0.7,
|
33 |
+
"candidate_count": 1
|
34 |
}
|
35 |
+
|
36 |
try:
|
37 |
response = requests.post(url, headers=headers, json=data)
|
38 |
if response.status_code == 200:
|
39 |
result = response.json()
|
40 |
+
treatment = result.get("candidates", [{}])[0].get("content", "No treatment suggestions found.")
|
41 |
return treatment
|
42 |
else:
|
43 |
+
logging.error(f"API Error: {response.status_code} - {response.text}")
|
44 |
+
return f"API Error: {response.status_code}"
|
45 |
except Exception as e:
|
46 |
logging.error(f"Error fetching treatment suggestions: {str(e)}")
|
47 |
return "Error retrieving treatment details."
|