Spaces:
Running
Running
import gradio as gr | |
import pandas as pd | |
from mock_models.crop_model import MockCropModel | |
from mock_models.chat_engine import AgriculturalChatEngine | |
# Initialize mock models | |
crop_model = MockCropModel() | |
chat_engine = AgriculturalChatEngine() | |
# ---------------------- | |
# Core functionality | |
# ---------------------- | |
def get_crop_recommendation(soil_type, climate, file_input): | |
"""Process inputs and generate recommendations""" | |
df = crop_model.predict(soil_type, climate) | |
if file_input: | |
try: | |
uploaded_data = pd.read_csv(file_input.name) | |
df['Uploaded Data'] = uploaded_data.mean().to_dict() | |
except: | |
pass | |
return df | |
def handle_chat(query, history): | |
"""Process chat queries""" | |
response = chat_engine.generate_response(query) | |
history.append((query, response)) | |
return history, "" | |
# ---------------------- | |
# UI Components | |
# ---------------------- | |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="emerald"), title="CropSeek-LLM") as demo: | |
# ---------------------- | |
# Enhanced Header | |
# ---------------------- | |
gr.HTML(""" | |
<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);"> | |
<img src="https://huggingface.co/spaces/DARJYO/CropSeek-LLM/resolve/main/assets/logo.png" | |
style="height:100px; filter: drop-shadow(2px 2px 4px #00000060);"> | |
</div> | |
""") | |
# Chat Interface | |
with gr.Tab("π£οΈ Agronomist"): | |
chatbot = gr.Chatbot(height=400, label="Crop Insight Engine") | |
chat_input = gr.Textbox(placeholder="Input agricultural parameters...Ask about crops, pests, or farming practices...") | |
chat_input.submit(handle_chat, [chat_input, chatbot], [chatbot, chat_input]) | |
# Data Analysis Interface | |
with gr.Tab("π Crop Advisor"): | |
with gr.Row(): | |
soil_type = gr.Dropdown( | |
["Loamy", "Clay", "Sandy"], | |
label="Soil Type", | |
value="Loamy" | |
) | |
climate_zone = gr.Dropdown( | |
["Tropical", "Temperate", "Arid"], | |
label="Climate Zone", | |
value="Tropical" | |
) | |
upload_btn = gr.UploadButton("π Upload Soil Analysis (CSV)", file_types=[".csv"]) | |
analyze_btn = gr.Button("π Analyze Conditions", variant="primary") | |
results = gr.Dataframe( | |
headers=["Crop", "Confidence", "Soil Type", "Climate Zone"], | |
interactive=False, | |
wrap=True | |
) | |
analyze_btn.click( | |
fn=get_crop_recommendation, | |
inputs=[soil_type, climate_zone, upload_btn], | |
outputs=results | |
) | |
# Footer | |
gr.Markdown("---") | |
with gr.Row(): | |
gr.Markdown("**System Status:** β Operational") | |
gr.Markdown("**Version:** 1.0.0") | |
gr.Markdown("**Data Updated:** 2025-05-15") | |
# ---------------------- | |
# Launch Application | |
# ---------------------- | |
if __name__ == "__main__": | |
demo.launch() |