Briankabiru commited on
Commit
e22b1b1
1 Parent(s): d47442f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -0
app.py CHANGED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ # Define the function to call the model hosted on Hugging Face
5
+ def get_fertilizer_recommendation(crop_name, target_yield, field_size, ph_water, organic_carbon, total_nitrogen, phosphorus, potassium, soil_moisture):
6
+ # Replace this with the URL of your Hugging Face model
7
+ url = "https://api-inference.huggingface.co/models/your-model-name"
8
+ headers = {"Authorization": "Bearer YOUR_HUGGING_FACE_API_KEY"}
9
+
10
+ # Define the input payload
11
+ payload = {
12
+ 'Crop Name': [crop_name],
13
+ 'Target Yield': [target_yield],
14
+ 'Field Size': [field_size],
15
+ 'pH (water)': [ph_water],
16
+ 'Organic Carbon': [organic_carbon],
17
+ 'Total Nitrogen': [total_nitrogen],
18
+ 'Phosphorus (M3)': [phosphorus],
19
+ 'Potassium (exch.)': [potassium],
20
+ 'Soil moisture': [soil_moisture]
21
+ }
22
+
23
+ # Make the request to the model
24
+ response = requests.post(url, headers=headers, json=payload)
25
+ result = response.json()
26
+
27
+ # Extract the relevant output fields
28
+ output = f"""
29
+ Predicted Fertilizer Requirements:
30
+ Nitrogen (N) Need: {result['Nitrogen (N) Need']}
31
+ Phosphorus (P2O5) Need: {result['Phosphorus (P2O5) Need']}
32
+ Potassium (K2O) Need: {result['Potassium (K2O) Need']}
33
+ Organic Matter Need: {result['Organic Matter Need']}
34
+ Lime Need: {result['Lime Need']}
35
+ Lime Application - Requirement: {result['Lime Application - Requirement']}
36
+ Organic Matter Application - Requirement: {result['Organic Matter Application - Requirement']}
37
+ 1st Application - Requirement (1): {result['1st Application - Requirement (1)']}
38
+ 1st Application - Requirement (2): {result['1st Application - Requirement (2)']}
39
+ Lime Application - Instruction: {result['Lime Application - Instruction']}
40
+ Lime Application: {result['Lime Application']}
41
+ Organic Matter Application - Instruction: {result['Organic Matter Application - Instruction']}
42
+ Organic Matter Application: {result['Organic Matter Application']}
43
+ 1st Application: {result['1st Application']}
44
+ 1st Application - Type fertilizer (1): {result['1st Application - Type fertilizer (1)']}
45
+ 1st Application - Type fertilizer (2): {result['1st Application - Type fertilizer (2)']}
46
+ """
47
+ return output
48
+
49
+ # Create the Gradio interface
50
+ interface = gr.Interface(
51
+ fn=get_fertilizer_recommendation,
52
+ inputs=[
53
+ gr.inputs.Textbox(label="Crop Name"),
54
+ gr.inputs.Number(label="Target Yield"),
55
+ gr.inputs.Number(label="Field Size"),
56
+ gr.inputs.Number(label="pH (water)"),
57
+ gr.inputs.Number(label="Organic Carbon"),
58
+ gr.inputs.Number(label="Total Nitrogen"),
59
+ gr.inputs.Number(label="Phosphorus (M3)"),
60
+ gr.inputs.Number(label="Potassium (exch.)"),
61
+ gr.inputs.Number(label="Soil moisture"),
62
+ ],
63
+ outputs="text",
64
+ title="Fertilizer Application Advisor",
65
+ description="Input the details of your field and get fertilizer recommendations."
66
+ )
67
+
68
+ # Launch the interface
69
+ interface.launch()