Update app.py
Browse files
app.py
CHANGED
|
@@ -183,6 +183,22 @@ def split_and_search(text:str):
|
|
| 183 |
time.sleep(1)
|
| 184 |
return all_data
|
| 185 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
#use it here :
|
| 187 |
#process_plants(plants)
|
| 188 |
|
|
@@ -206,5 +222,23 @@ with gr.Blocks(title="AI-Powered Medicinal Plants Database") as app:
|
|
| 206 |
outputs=output_area #json_output
|
| 207 |
)
|
| 208 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
if __name__ == "__main__":
|
| 210 |
app.launch(debug=True, share=False)
|
|
|
|
| 183 |
time.sleep(1)
|
| 184 |
return all_data
|
| 185 |
|
| 186 |
+
#For View:
|
| 187 |
+
def get_all_plants() -> List[Dict]:
|
| 188 |
+
"""Retrieve all plants from database"""
|
| 189 |
+
try:
|
| 190 |
+
conn = sqlite3.connect(DB_NAME)
|
| 191 |
+
conn.row_factory = sqlite3.Row
|
| 192 |
+
cursor = conn.cursor()
|
| 193 |
+
cursor.execute("SELECT `_rowid_`,* FROM plants ORDER BY `_rowid_` DESC")
|
| 194 |
+
plants = [dict(row) for row in cursor.fetchall()]
|
| 195 |
+
conn.close()
|
| 196 |
+
return plants
|
| 197 |
+
except Exception as e:
|
| 198 |
+
print(f"Database retrieval error: {e}")
|
| 199 |
+
return [{"Error": "Failed to retrieve data from database"}]
|
| 200 |
+
|
| 201 |
+
|
| 202 |
#use it here :
|
| 203 |
#process_plants(plants)
|
| 204 |
|
|
|
|
| 222 |
outputs=output_area #json_output
|
| 223 |
)
|
| 224 |
|
| 225 |
+
with gr.Tab("View Database"):
|
| 226 |
+
gr.Markdown("### Stored Plant Information")
|
| 227 |
+
with gr.Row():
|
| 228 |
+
refresh_btn = gr.Button("Refresh Data", variant="secondary")
|
| 229 |
+
clear_db = gr.Button("Clear Database", variant="stop")
|
| 230 |
+
|
| 231 |
+
db_table = gr.Dataframe(
|
| 232 |
+
headers=["id", "name", "scientific_name", "description"],
|
| 233 |
+
datatype=["number", "str", "str", "str"],
|
| 234 |
+
col_count=(4, "fixed"),
|
| 235 |
+
interactive=True
|
| 236 |
+
)
|
| 237 |
+
|
| 238 |
+
refresh_btn.click(
|
| 239 |
+
fn=get_all_plants,
|
| 240 |
+
outputs=db_table
|
| 241 |
+
)
|
| 242 |
+
|
| 243 |
if __name__ == "__main__":
|
| 244 |
app.launch(debug=True, share=False)
|