Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,92 +1,87 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
|
4 |
-
|
5 |
-
#
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
gr.HTML("""
|
9 |
-
<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);">
|
10 |
<img src="https://huggingface.co/spaces/DARJYO/CropSeek-LLM/resolve/main/assets/logo.png"
|
11 |
style="height:80px; margin-bottom:20px;">
|
12 |
-
|
13 |
""")
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
# ----------------------
|
18 |
with gr.Tab("π± Field Analysis Console"):
|
19 |
with gr.Row():
|
20 |
with gr.Column(scale=2):
|
21 |
analysis_log = gr.Chatbot(
|
22 |
label="Crop Diagnosis History",
|
23 |
avatar_images=("π§πΎ", "π€"),
|
24 |
-
height=
|
25 |
-
show_label=True,
|
26 |
-
container=True
|
27 |
)
|
28 |
-
|
29 |
with gr.Column(scale=1):
|
30 |
-
gr.Markdown("### π¦οΈ Environmental Parameters")
|
31 |
field_input = gr.Textbox(
|
32 |
-
label="Describe Conditions:",
|
33 |
-
placeholder="e.g. 'Clay soil in tropical climate with
|
34 |
-
lines=3
|
35 |
-
)
|
36 |
-
|
37 |
-
gr.Examples(
|
38 |
-
examples=[
|
39 |
-
["Sandy loam soil with temperate climate and irrigation access"],
|
40 |
-
["Arid region with limited water resources and alkaline soil"],
|
41 |
-
["Volcanic soil in subtropical highland climate"]
|
42 |
-
],
|
43 |
-
inputs=field_input,
|
44 |
-
label="π‘ Try Example Scenarios:"
|
45 |
)
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
51 |
with gr.Row():
|
52 |
soil_dd = gr.Dropdown(
|
53 |
-
["Loamy", "Clay", "Sandy",
|
54 |
label="Soil Composition",
|
55 |
-
info="
|
56 |
)
|
57 |
climate_dd = gr.Dropdown(
|
58 |
-
["Tropical", "Temperate", "Arid",
|
59 |
label="Climate Profile",
|
60 |
-
info="
|
61 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
"Value": ["Loamy", "Tropical", "Pepper"],
|
69 |
-
"Recommendation": ["Ideal for roots", "Optimal temp range", "High market demand"]
|
70 |
-
},
|
71 |
-
headers=["Parameter", "Value", "Recommendation"],
|
72 |
-
interactive=False,
|
73 |
-
wrap=True
|
74 |
-
)
|
75 |
|
76 |
-
|
77 |
-
# Footer & Status
|
78 |
-
# ----------------------
|
79 |
-
gr.Markdown("---")
|
80 |
-
with gr.Row():
|
81 |
-
gr.Markdown(f"**Last Updated:** {datetime.now().strftime('%Y-%m-%d %H:%M')}")
|
82 |
-
gr.Markdown("**System Status:** π’ Operational")
|
83 |
-
gr.Markdown("**Version:** 2.1.0")
|
84 |
-
|
85 |
-
gr.Markdown("""
|
86 |
<div style="text-align: center; padding: 15px; background-color: #f8f9fa; border-radius: 8px; margin-top: 20px;">
|
87 |
<small>Β© 2025 DARJYO/CropSeek-LLM</small>
|
88 |
</div>
|
89 |
""")
|
90 |
|
91 |
-
|
92 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
|
4 |
+
def get_crop_recommendation(soil_type, climate, history):
|
5 |
+
# Replace with your actual model inference logic
|
6 |
+
recommendations = {
|
7 |
+
"soil": soil_type,
|
8 |
+
"climate": climate,
|
9 |
+
"recommended_crops": ["Pepper", "Tomato", "Chilli"],
|
10 |
+
"confidence": [0.85, 0.76, 0.68]
|
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"; background: linear-gradient(to right, #2c5f2d, #97bc62); padding: 20px; border-radius: 10px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
|
22 |
<img src="https://huggingface.co/spaces/DARJYO/CropSeek-LLM/resolve/main/assets/logo.png"
|
23 |
style="height:80px; margin-bottom:20px;">
|
24 |
+
</div>
|
25 |
""")
|
26 |
+
|
27 |
+
gr.Markdown("### πΎ Agricultural Intelligence 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("""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
<div style="text-align: center; padding: 15px; background-color: #f8f9fa; border-radius: 8px; margin-top: 20px;">
|
82 |
<small>Β© 2025 DARJYO/CropSeek-LLM</small>
|
83 |
</div>
|
84 |
""")
|
85 |
|
86 |
+
|
87 |
+
demo.launch()
|