Spaces:
Runtime error
Runtime error
import gradio as gr | |
import pandas as pd | |
def get_crop_recommendation(soil_type, climate, history): | |
# Replace with your actual model inference logic | |
recommendations = { | |
"soil": soil_type, | |
"climate": climate, | |
"recommended_crops": ["Pepper", "Tomato", "Chilli"], | |
"confidence": [0.85, 0.76, 0.68] | |
} | |
return pd.DataFrame(recommendations) | |
def analyze_conditions(query, history): | |
# Condition analysis handler (connect to your LLM) | |
response = f"π± CropAI Analysis: Optimal cultivation patterns suggest {get_crop_recommendation('Loam', 'Tropical', '').iloc[0]['recommended_crops'][0]} for these conditions." | |
return response | |
with gr.Blocks(theme=gr.themes.Soft(), title="CropSeek-LLM") as demo: | |
gr.HTML(""" | |
<div style="text-align:center"; background: linear-gradient(to right, #2c5f2d, #97bc62); padding: 20px; border-radius: 10px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);"> | |
<img src="https://huggingface.co/spaces/DARJYO/CropSeek-LLM/resolve/main/assets/logo.png" | |
style="height:80px; margin-bottom:20px;"> | |
</div> | |
""") | |
gr.Markdown("### πΎ Agricultural Intelligence System") | |
with gr.Tab("π± Field Analysis Console"): | |
with gr.Row(): | |
with gr.Column(scale=2): | |
analysis_log = gr.Chatbot( | |
label="Crop Diagnosis History", | |
avatar_images=("π§πΎ", "π€"), | |
height=400 | |
) | |
with gr.Column(scale=1): | |
field_input = gr.Textbox( | |
label="Describe Soil & Climate Conditions:", | |
placeholder="e.g. 'Clay soil in tropical climate with moderate rainfall...'" | |
) | |
analyze_btn = gr.Button("π¦οΈ Analyze Agricultural Patterns", variant="primary") | |
analyze_btn.click( | |
analyze_conditions, | |
[field_input, analysis_log], | |
[field_input, analysis_log] | |
) | |
with gr.Tab("π Yield Optimization Advisor"): | |
with gr.Row(): | |
soil_dd = gr.Dropdown( | |
["Loamy", "Clay", "Sandy"], | |
label="Soil Composition", | |
info="Select predominant soil type" | |
) | |
climate_dd = gr.Dropdown( | |
["Tropical", "Temperate", "Arid"], | |
label="Climate Profile", | |
info="Select regional climate pattern" | |
) | |
farm_data = gr.File( | |
label="Upload Field Sensor Data (CSV)", | |
file_types=[".csv"] | |
) | |
simulate_btn = gr.Button("π Generate Cultivation Plan", variant="primary") | |
results = gr.Dataframe( | |
headers=["Parameter", "Value", "Recommendation"], | |
interactive=False, | |
wrap=True, | |
datatype=["str", "number", "str"] | |
) | |
simulate_btn.click( | |
fn=get_crop_recommendation, | |
inputs=[soil_dd, climate_dd, farm_data], | |
outputs=results | |
) | |
gr.Markdown(""" | |
<div style="text-align: center; padding: 15px; background-color: #f8f9fa; border-radius: 8px; margin-top: 20px;"> | |
<small>Β© 2025 DARJYO/CropSeek-LLM</small> | |
</div> | |
""") | |
demo.launch() |