persadian commited on
Commit
077c563
Β·
verified Β·
1 Parent(s): a76e990

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -69
app.py CHANGED
@@ -1,87 +1,84 @@
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()
 
1
  import gradio as gr
2
  import pandas as pd
3
+ from mock_models.crop_model import MockCropModel
4
+ from mock_models.chat_engine import AgriculturalChatEngine
5
 
6
+ # Initialize mock models
7
+ crop_model = MockCropModel()
8
+ chat_engine = AgriculturalChatEngine()
 
 
 
 
 
 
9
 
10
+ # ----------------------
11
+ # Core functionality
12
+ # ----------------------
13
+ def get_crop_recommendation(soil_type, climate, file_input):
14
+ """Process inputs and generate recommendations"""
15
+ df = crop_model.predict(soil_type, climate)
 
 
 
 
 
 
16
 
17
+ if file_input:
18
+ try:
19
+ uploaded_data = pd.read_csv(file_input.name)
20
+ df['Uploaded Data'] = uploaded_data.mean().to_dict()
21
+ except:
22
+ pass
23
+
24
+ return df
25
+
26
+ def handle_chat(query, history):
27
+ """Process chat queries"""
28
+ response = chat_engine.generate_response(query)
29
+ history.append((query, response))
30
+ return history, ""
31
+
32
+ # ----------------------
33
+ # UI Components
34
+ # ----------------------
35
+ with gr.Blocks(theme=gr.themes.Soft(), title="CropSeek LLM") as demo:
36
+ # Header Section
37
+ gr.Markdown("# 🌐 CropSeek LLM")
38
+ gr.Markdown("## AI-Driven Agricultural Decision Support System")
39
 
40
+ # Chat Interface
41
+ with gr.Tab("πŸ—£οΈ Virtual Agronomist"):
42
+ chatbot = gr.Chatbot(height=400, label="Farm Assistant")
43
+ chat_input = gr.Textbox(placeholder="Ask about crops, pests, or farming practices...")
44
+ chat_input.submit(handle_chat, [chat_input, chatbot], [chatbot, chat_input])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
+ # Data Analysis Interface
47
+ with gr.Tab("πŸ“Š Crop Advisor"):
48
  with gr.Row():
49
+ soil_type = gr.Dropdown(
50
+ ["Loamy", "Clay", "Sandy"],
51
+ label="Soil Type",
52
+ value="Loamy"
53
  )
54
+ climate_zone = gr.Dropdown(
55
+ ["Tropical", "Temperate", "Arid"],
56
+ label="Climate Zone",
57
+ value="Tropical"
58
  )
59
+ upload_btn = gr.UploadButton("πŸ“ Upload Soil Analysis (CSV)", file_types=[".csv"])
60
+ analyze_btn = gr.Button("🚜 Analyze Conditions", variant="primary")
 
 
 
61
  results = gr.Dataframe(
62
+ headers=["Crop", "Confidence", "Soil Type", "Climate Zone"],
63
  interactive=False,
64
+ wrap=True
 
65
  )
66
 
67
+ analyze_btn.click(
68
  fn=get_crop_recommendation,
69
+ inputs=[soil_type, climate_zone, upload_btn],
70
  outputs=results
71
  )
72
+
73
+ # Footer
74
+ gr.Markdown("---")
75
+ with gr.Row():
76
+ gr.Markdown("**System Status:** βœ… Operational")
77
+ gr.Markdown("**Version:** 1.0.0")
78
+ gr.Markdown("**Data Updated:** 2023-08-15")
79
 
80
+ # ----------------------
81
+ # Launch Application
82
+ # ----------------------
83
+ if __name__ == "__main__":
84
+ demo.launch()