File size: 3,018 Bytes
e22b1b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import gradio as gr
import requests

# Define the function to call the model hosted on Hugging Face
def get_fertilizer_recommendation(crop_name, target_yield, field_size, ph_water, organic_carbon, total_nitrogen, phosphorus, potassium, soil_moisture):
    # Replace this with the URL of your Hugging Face model
    url = "https://api-inference.huggingface.co/models/your-model-name"
    headers = {"Authorization": "Bearer YOUR_HUGGING_FACE_API_KEY"}

    # Define the input payload
    payload = {
        'Crop Name': [crop_name],
        'Target Yield': [target_yield],
        'Field Size': [field_size],
        'pH (water)': [ph_water],
        'Organic Carbon': [organic_carbon],
        'Total Nitrogen': [total_nitrogen],
        'Phosphorus (M3)': [phosphorus],
        'Potassium (exch.)': [potassium],
        'Soil moisture': [soil_moisture]
    }

    # Make the request to the model
    response = requests.post(url, headers=headers, json=payload)
    result = response.json()

    # Extract the relevant output fields
    output = f"""
    Predicted Fertilizer Requirements:
    Nitrogen (N) Need: {result['Nitrogen (N) Need']}
    Phosphorus (P2O5) Need: {result['Phosphorus (P2O5) Need']}
    Potassium (K2O) Need: {result['Potassium (K2O) Need']}
    Organic Matter Need: {result['Organic Matter Need']}
    Lime Need: {result['Lime Need']}
    Lime Application - Requirement: {result['Lime Application - Requirement']}
    Organic Matter Application - Requirement: {result['Organic Matter Application - Requirement']}
    1st Application - Requirement (1): {result['1st Application - Requirement (1)']}
    1st Application - Requirement (2): {result['1st Application - Requirement (2)']}
    Lime Application - Instruction: {result['Lime Application - Instruction']}
    Lime Application: {result['Lime Application']}
    Organic Matter Application - Instruction: {result['Organic Matter Application - Instruction']}
    Organic Matter Application: {result['Organic Matter Application']}
    1st Application: {result['1st Application']}
    1st Application - Type fertilizer (1): {result['1st Application - Type fertilizer (1)']}
    1st Application - Type fertilizer (2): {result['1st Application - Type fertilizer (2)']}
    """
    return output

# Create the Gradio interface
interface = gr.Interface(
    fn=get_fertilizer_recommendation,
    inputs=[
        gr.inputs.Textbox(label="Crop Name"),
        gr.inputs.Number(label="Target Yield"),
        gr.inputs.Number(label="Field Size"),
        gr.inputs.Number(label="pH (water)"),
        gr.inputs.Number(label="Organic Carbon"),
        gr.inputs.Number(label="Total Nitrogen"),
        gr.inputs.Number(label="Phosphorus (M3)"),
        gr.inputs.Number(label="Potassium (exch.)"),
        gr.inputs.Number(label="Soil moisture"),
    ],
    outputs="text",
    title="Fertilizer Application Advisor",
    description="Input the details of your field and get fertilizer recommendations."
)

# Launch the interface
interface.launch()