persadian commited on
Commit
af0eb41
Β·
verified Β·
1 Parent(s): 990f906

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -62
app.py CHANGED
@@ -1,92 +1,87 @@
1
  import gradio as gr
2
- from datetime import datetime
3
 
4
- with gr.Blocks(theme=gr.themes.Soft(primary_hue="emerald"), title="CropSeek-LLM") as demo:
5
- # ----------------------
6
- # Enhanced Header
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
- </div>
13
  """)
14
-
15
- # ----------------------
16
- # Main Analysis Interface
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=450,
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 1200mm rainfall...'",
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
- # Data Visualization Interface
49
- # ----------------------
50
- with gr.Tab("πŸ“ˆ Yield Optimization"):
 
 
 
 
51
  with gr.Row():
52
  soil_dd = gr.Dropdown(
53
- ["Loamy", "Clay", "Sandy", "Volcanic", "Peaty"],
54
  label="Soil Composition",
55
- info="USDA soil classification"
56
  )
57
  climate_dd = gr.Dropdown(
58
- ["Tropical", "Temperate", "Arid", "Mediterranean", "Continental"],
59
  label="Climate Profile",
60
- info="KΓΆppen climate classification"
61
  )
 
 
 
 
 
 
 
 
 
 
 
62
 
63
- with gr.Row():
64
- gr.Markdown("### Cultivation Plan Preview")
65
- results = gr.DataFrame(
66
- value={
67
- "Parameter": ["Soil Type", "Climate", "Top Crop"],
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
- if __name__ == "__main__":
92
- demo.launch()
 
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()