persadian commited on
Commit
64718b0
Β·
verified Β·
1 Parent(s): ea46c12

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -20
app.py CHANGED
@@ -11,12 +11,11 @@ def get_crop_recommendation(soil_type, climate, history):
11
  }
12
  return pd.DataFrame(recommendations)
13
 
14
- def chat_response(message, history):
15
- # Simple chat handler (connect to your LLM)
16
- response = f"Agricultural Assistant: I recommend considering {get_crop_recommendation('Loam', 'Tropical', '').iloc[0]['recommended_crops'][0]} for your conditions."
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-Powered Crop Recommendation System")
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("Data Analysis"):
36
- file_input = gr.File(label="Upload Farm Data (CSV)")
37
  with gr.Row():
38
- soil_dd = gr.Dropdown(["Loamy", "Clay", "Sandy"], label="Soil Type")
39
- climate_dd = gr.Dropdown(["Tropical", "Temperate", "Arid"], label="Climate Zone")
40
- analyze_btn = gr.Button("Analyze Conditions")
41
- results = gr.Dataframe(headers=["Parameter", "Value"], interactive=False)
 
 
 
 
 
 
 
 
42
 
43
  analyze_btn.click(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  fn=get_crop_recommendation,
45
- inputs=[soil_dd, climate_dd, file_input],
46
  outputs=results
47
  )
48
 
49
- gr.Markdown("---\n*Demo for Preview | v1.2*")
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()