Spaces:
Running
Running
File size: 3,114 Bytes
a147a85 af0eb41 077c563 a147a85 077c563 af0eb41 077c563 af0eb41 077c563 dc8e3e4 08cc158 dc8e3e4 475b3cf 077c563 59e7fe0 077c563 af0eb41 077c563 dc896b6 077c563 dc896b6 077c563 dc896b6 077c563 af0eb41 077c563 af0eb41 077c563 af0eb41 6cac93a 077c563 af0eb41 077c563 af0eb41 077c563 10b31c6 dc896b6 077c563 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
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() |