Nadeem005 commited on
Commit
faf0b3d
·
verified ·
1 Parent(s): 65312af

Update app.py

Browse files

create the application file

Files changed (1) hide show
  1. app.py +71 -1
app.py CHANGED
@@ -131,4 +131,74 @@ Please ask a question about the agricultural data!"""
131
 
132
  **SQL Query:**
133
  ```sql
134
- {sql_query}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
 
132
  **SQL Query:**
133
  ```sql
134
+ {sql_query}
135
+ ```
136
+
137
+ **Result:**
138
+ {result}
139
+ """
140
+ return response
141
+
142
+ except Exception as e:
143
+ error_msg = f"Error: {str(e)}"
144
+ print(error_msg)
145
+ return f"""❌ **Error occurred:**
146
+
147
+ {error_msg}
148
+
149
+ **Question:** {question}
150
+
151
+ Please try rephrasing your question or ask about different data."""
152
+
153
+ # --- 6. CREATE GRADIO INTERFACE ---
154
+ with gr.Blocks(title="Project Samarth - Agriculture Database Query") as demo:
155
+ gr.Markdown("""
156
+ # 🌾 Project Samarth - Agriculture Database Assistant
157
+
158
+ Ask questions about agricultural data in natural language!
159
+
160
+ **Example Questions:**
161
+ - What was the rice production in Bihar in 2015?
162
+ - Which state had the highest wheat production?
163
+ - Show me rainfall data for Kerala
164
+ """)
165
+
166
+ with gr.Row():
167
+ question_input = gr.Textbox(
168
+ label="Your Question",
169
+ placeholder="e.g., What was the total rice production in 2020?",
170
+ lines=2
171
+ )
172
+
173
+ with gr.Row():
174
+ submit_btn = gr.Button("Submit Query", variant="primary")
175
+ clear_btn = gr.Button("Clear")
176
+
177
+ output = gr.Markdown(label="Answer")
178
+
179
+ submit_btn.click(
180
+ fn=run_query,
181
+ inputs=question_input,
182
+ outputs=output
183
+ )
184
+
185
+ clear_btn.click(
186
+ fn=lambda: ("", ""),
187
+ inputs=None,
188
+ outputs=[question_input, output]
189
+ )
190
+
191
+ gr.Examples(
192
+ examples=[
193
+ "What was the rice production in Bihar in 2015?",
194
+ "Which state had the highest wheat production?",
195
+ "Show me all states with their crop data",
196
+ "What is the average rainfall in Punjab?"
197
+ ],
198
+ inputs=question_input
199
+ )
200
+
201
+ # --- 7. LAUNCH THE APP ---
202
+ if __name__ == "__main__":
203
+ demo.launch()
204
+