Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,12 +11,11 @@ def get_crop_recommendation(soil_type, climate, history):
|
|
11 |
}
|
12 |
return pd.DataFrame(recommendations)
|
13 |
|
14 |
-
def
|
15 |
-
#
|
16 |
-
response = f"
|
17 |
return response
|
18 |
|
19 |
-
|
20 |
with gr.Blocks(theme=gr.themes.Soft(), title="CropSeek LLM") as demo:
|
21 |
gr.HTML("""
|
22 |
<div style="text-align:center">
|
@@ -25,28 +24,59 @@ with gr.Blocks(theme=gr.themes.Soft(), title="CropSeek LLM") as demo:
|
|
25 |
</div>
|
26 |
""")
|
27 |
|
28 |
-
gr.Markdown("### AI-
|
29 |
-
|
30 |
-
with gr.Tab("Chat Interface"):
|
31 |
-
chatbot = gr.Chatbot(height=400)
|
32 |
-
msg = gr.Textbox(label="Ask about crops...")
|
33 |
-
msg.submit(chat_response, [msg, chatbot], [msg, chatbot])
|
34 |
|
35 |
-
with gr.Tab("
|
36 |
-
file_input = gr.File(label="Upload Farm Data (CSV)")
|
37 |
with gr.Row():
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
analyze_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
fn=get_crop_recommendation,
|
45 |
-
inputs=[soil_dd, climate_dd,
|
46 |
outputs=results
|
47 |
)
|
48 |
|
49 |
-
gr.Markdown("---\n*
|
50 |
-
|
51 |
-
demo.launch()
|
52 |
|
|
|
|
11 |
}
|
12 |
return pd.DataFrame(recommendations)
|
13 |
|
14 |
+
def analyze_conditions(query, history):
|
15 |
+
# Condition analysis handler (connect to your LLM)
|
16 |
+
response = f"π± CropAI Analysis: Optimal cultivation patterns suggest {get_crop_recommendation('Loam', 'Tropical', '').iloc[0]['recommended_crops'][0]} for these conditions."
|
17 |
return response
|
18 |
|
|
|
19 |
with gr.Blocks(theme=gr.themes.Soft(), title="CropSeek LLM") as demo:
|
20 |
gr.HTML("""
|
21 |
<div style="text-align:center">
|
|
|
24 |
</div>
|
25 |
""")
|
26 |
|
27 |
+
gr.Markdown("### πΎ AI-Driven Crop Optimization System")
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
with gr.Tab("π± Field Analysis Console"):
|
|
|
30 |
with gr.Row():
|
31 |
+
with gr.Column(scale=2):
|
32 |
+
analysis_log = gr.Chatbot(
|
33 |
+
label="Crop Diagnosis History",
|
34 |
+
avatar_images=("π§πΎ", "π€"),
|
35 |
+
height=400
|
36 |
+
)
|
37 |
+
with gr.Column(scale=1):
|
38 |
+
field_input = gr.Textbox(
|
39 |
+
label="Describe Soil & Climate Conditions:",
|
40 |
+
placeholder="e.g. 'Clay soil in tropical climate with moderate rainfall...'"
|
41 |
+
)
|
42 |
+
analyze_btn = gr.Button("π¦οΈ Analyze Agricultural Patterns", variant="primary")
|
43 |
|
44 |
analyze_btn.click(
|
45 |
+
analyze_conditions,
|
46 |
+
[field_input, analysis_log],
|
47 |
+
[field_input, analysis_log]
|
48 |
+
)
|
49 |
+
|
50 |
+
with gr.Tab("π Yield Optimization Advisor"):
|
51 |
+
with gr.Row():
|
52 |
+
soil_dd = gr.Dropdown(
|
53 |
+
["Loamy", "Clay", "Sandy"],
|
54 |
+
label="Soil Composition",
|
55 |
+
info="Select predominant soil type"
|
56 |
+
)
|
57 |
+
climate_dd = gr.Dropdown(
|
58 |
+
["Tropical", "Temperate", "Arid"],
|
59 |
+
label="Climate Profile",
|
60 |
+
info="Select regional climate pattern"
|
61 |
+
)
|
62 |
+
farm_data = gr.File(
|
63 |
+
label="Upload Field Sensor Data (CSV)",
|
64 |
+
file_types=[".csv"]
|
65 |
+
)
|
66 |
+
simulate_btn = gr.Button("π Generate Cultivation Plan", variant="primary")
|
67 |
+
results = gr.Dataframe(
|
68 |
+
headers=["Parameter", "Value", "Recommendation"],
|
69 |
+
interactive=False,
|
70 |
+
wrap=True,
|
71 |
+
datatype=["str", "number", "str"]
|
72 |
+
)
|
73 |
+
|
74 |
+
simulate_btn.click(
|
75 |
fn=get_crop_recommendation,
|
76 |
+
inputs=[soil_dd, climate_dd, farm_data],
|
77 |
outputs=results
|
78 |
)
|
79 |
|
80 |
+
gr.Markdown("---\n*Agricultural Intelligence Platform | v2.1*")
|
|
|
|
|
81 |
|
82 |
+
demo.launch()
|