Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,87 +1,84 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
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 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
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 |
-
|
|
|
51 |
with gr.Row():
|
52 |
-
|
53 |
-
["Loamy", "Clay", "Sandy"],
|
54 |
-
label="Soil
|
55 |
-
|
56 |
)
|
57 |
-
|
58 |
-
["Tropical", "Temperate", "Arid"],
|
59 |
-
label="Climate
|
60 |
-
|
61 |
)
|
62 |
-
|
63 |
-
|
64 |
-
file_types=[".csv"]
|
65 |
-
)
|
66 |
-
simulate_btn = gr.Button("π Generate Cultivation Plan", variant="primary")
|
67 |
results = gr.Dataframe(
|
68 |
-
headers=["
|
69 |
interactive=False,
|
70 |
-
wrap=True
|
71 |
-
datatype=["str", "number", "str"]
|
72 |
)
|
73 |
|
74 |
-
|
75 |
fn=get_crop_recommendation,
|
76 |
-
inputs=[
|
77 |
outputs=results
|
78 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
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()
|
|
|
|
|
|