Engineer786 commited on
Commit
e0b0834
·
verified ·
1 Parent(s): af82b58

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +100 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from streamlit_extras.colored_header import colored_header
4
+ from streamlit_extras.add_vertical_space import add_vertical_space
5
+ from groq import Groq
6
+
7
+ # Initialize Groq API
8
+ GROQ_API_KEY = "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"
9
+ client = Groq(api_key=GROQ_API_KEY)
10
+
11
+ # Function to query Groq API
12
+ def query_groq(prompt, model="llama3-8b-8192"):
13
+ chat_completion = client.chat.completions.create(
14
+ messages=[{"role": "user", "content": prompt}],
15
+ model=model,
16
+ )
17
+ return chat_completion.choices[0].message.content
18
+
19
+ # Streamlit UI
20
+ st.set_page_config(
21
+ page_title="Crop Yield Insights",
22
+ page_icon="🌾",
23
+ layout="wide",
24
+ )
25
+
26
+ # Sidebar
27
+ with st.sidebar:
28
+ st.image("https://cdn-icons-png.flaticon.com/512/868/868909.png", width=120)
29
+ st.title("Crop Yield Assistant 🌱")
30
+ st.markdown("Get recommendations and predictions for crops based on data insights.")
31
+ add_vertical_space(3)
32
+ st.info("Upload your CSV file to get started!")
33
+
34
+ # Main app
35
+ st.title("🌾 Crop Yield Insights")
36
+ st.markdown("Upload your dataset and select an ID to get relevant insights, predictions, and recommendations.")
37
+
38
+ # File uploader
39
+ uploaded_file = st.file_uploader("Upload your CSV file", type=["csv"], accept_multiple_files=False)
40
+
41
+ if uploaded_file:
42
+ df = pd.read_csv(uploaded_file)
43
+
44
+ # Data preprocessing
45
+ if df.isnull().sum().any():
46
+ st.warning("Missing values detected. Filling with median values.")
47
+ df.fillna(df.median(numeric_only=True), inplace=True)
48
+
49
+ # Display dataset preview
50
+ st.subheader("📊 Dataset Overview")
51
+ st.dataframe(df.head())
52
+
53
+ # Ensure there is an 'ID' column
54
+ if 'ID' not in df.columns:
55
+ st.error("The dataset must contain an 'ID' column.")
56
+ else:
57
+ # Select ID
58
+ record_id = st.selectbox("Select an ID:", df['ID'].unique())
59
+
60
+ if st.button("Generate Insights"):
61
+ # Generate insights
62
+ record = df[df['ID'] == record_id]
63
+
64
+ if record.empty:
65
+ st.error(f"No record found for ID: {record_id}")
66
+ else:
67
+ soil_quality = record.iloc[0]['Soil_Quality']
68
+ seed_variety = record.iloc[0]['Seed_Variety']
69
+ fertilizer_amount = record.iloc[0]['Fertilizer_Amount_kg_per_hectare']
70
+ sunny_days = record.iloc[0]['Sunny_Days']
71
+ rainfall = record.iloc[0]['Rainfall_mm']
72
+ irrigation_schedule = record.iloc[0]['Irrigation_Schedule']
73
+
74
+ prompt = (
75
+ f"The dataset includes the following information for ID {record_id}:\n"
76
+ f"- Soil Quality: {soil_quality}\n"
77
+ f"- Seed Variety: {seed_variety}\n"
78
+ f"- Fertilizer Amount (kg/ha): {fertilizer_amount}\n"
79
+ f"- Sunny Days: {sunny_days}\n"
80
+ f"- Rainfall (mm): {rainfall}\n"
81
+ f"- Irrigation Schedule: {irrigation_schedule}\n\n"
82
+ "Using this data, provide insights into expected crop yield, "
83
+ "recommendations for improving productivity, and potential challenges."
84
+ )
85
+
86
+ with st.spinner("Fetching insights..."):
87
+ response = query_groq(prompt)
88
+
89
+ st.success(f"🌟 Insights for ID {record_id}")
90
+ st.markdown(response)
91
+
92
+ else:
93
+ st.info("Please upload a CSV file to proceed.")
94
+
95
+ # Footer
96
+ st.markdown("---")
97
+ st.markdown(
98
+ "<h4 style='text-align: center;'>Powered by 🧠 Groq AI | Designed with ❤️ Streamlit</h4>",
99
+ unsafe_allow_html=True,
100
+ )
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ numpy
4
+ groq
5
+ streamlit-extras