-
Notifications
You must be signed in to change notification settings - Fork 1
/
AgricultureDemo.java
49 lines (39 loc) · 2.69 KB
/
AgricultureDemo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package org.example.agriculture;
import com.t4a.processor.AIProcessingException;
import com.t4a.processor.GeminiImageActionProcessor;
import lombok.extern.slf4j.Slf4j;
import org.example.image.GeminiImageExample;
import org.example.pojo.ProjectDashboard;
import java.net.MalformedURLException;
import java.net.URL;
@Slf4j
public class AgricultureDemo {
public static void main(String[] args) throws AIProcessingException, MalformedURLException {
GeminiImageActionProcessor processor = new GeminiImageActionProcessor();
String urlString ="https://raw.githubusercontent.com/spMohanty/PlantVillage-Dataset/master/raw/color/Corn_(maize)___healthy/00031d74-076e-4aef-b040-e068cd3576eb___R.S_HL%208315%20copy%202.jpg";
URL url = new URL(urlString);
log.info("starting analysis of healthy corn plant");
plantAnalsis(processor, url);
log.info("starting analysis of unhealthy corn plant");
urlString = "https://raw.githubusercontent.com/spMohanty/PlantVillage-Dataset/master/raw/color/Corn_(maize)___Northern_Leaf_Blight/0079c731-80f5-4fea-b6a2-4ff23a7ce139___RS_NLB%204121.JPG";
url = new URL(urlString);
plantAnalsisPojo(processor, url);
log.info("starting analysis of a unhealthy peach plant");
urlString = "https://github.com/spMohanty/PlantVillage-Dataset/blob/master/raw/color/Peach___Bacterial_spot/004118fe-b351-4cad-83ca-280c77f82eaa___Rutg._Bact.S%201818.JPG?raw=true";
url = new URL(urlString);
plantAnalsisPojo(processor, url);
urlString = "https://plant-diseases.uada.edu/img/plant-name/cabbage/cabbage_black_rot.jpg";
url = new URL(urlString);
plantAnalsisPojo(processor, url);
}
public static void plantAnalsis(GeminiImageActionProcessor processor, URL url) throws AIProcessingException {
String plantDetails = (String) processor.imageToJson(url, "cropType", "plantName", "healthPercentage", "waterPercentage", "soilPercentage", "sunlightPercentage", "temperature", "hasPest", "hasDisease", "hasNutrientDeficiency", "hasWaterDeficiency", "hasSunlightDeficiency", "hasSoilDeficiency", "hasTemperatureDeficiency", "hasFrost", "hasHeatWave", "hasDrought", "hasFlood", "typeOfDisease");
log.info(plantDetails.toString());
log.info(processor.imageToText(url, "based on image what action should i take on this plant?"));
}
public static void plantAnalsisPojo(GeminiImageActionProcessor processor, URL url) throws AIProcessingException {
Plant plantDetails = (Plant) processor.imageToPojo(url, Plant.class);
log.info(plantDetails.toString());
log.info(processor.imageToText(url, "based on image what action should i take on this plant?"));
}
}