Spaces:
Sleeping
Sleeping
Commit
·
d3e96d2
1
Parent(s):
1a4a78f
bug
Browse files- local_database.py +6 -6
local_database.py
CHANGED
|
@@ -32,18 +32,18 @@ def init_db():
|
|
| 32 |
cursor = conn.cursor()
|
| 33 |
|
| 34 |
# Table to track the source documents (e.g., 'healthy_maize.txt', 'user_guide.pdf')
|
| 35 |
-
cursor.execute(
|
| 36 |
CREATE TABLE IF NOT EXISTS documents (
|
| 37 |
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 38 |
name TEXT NOT NULL UNIQUE
|
| 39 |
)
|
| 40 |
-
|
| 41 |
)
|
| 42 |
print("Table 'documents' checked/created.")
|
| 43 |
|
| 44 |
# Table to store each chunk of content (text or image)
|
| 45 |
# The faiss_id will correspond to the row number in the FAISS index
|
| 46 |
-
cursor.execute(
|
| 47 |
CREATE TABLE IF NOT EXISTS chunks (
|
| 48 |
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 49 |
doc_id INTEGER,
|
|
@@ -52,7 +52,7 @@ def init_db():
|
|
| 52 |
page_num INTEGER,
|
| 53 |
FOREIGN KEY (doc_id) REFERENCES documents (id)
|
| 54 |
)
|
| 55 |
-
|
| 56 |
)
|
| 57 |
print("Table 'chunks' checked/created.")
|
| 58 |
|
|
@@ -101,8 +101,8 @@ def insert_analysis(conn, analysis_data):
|
|
| 101 |
:param analysis_data:
|
| 102 |
:return: project id
|
| 103 |
"""
|
| 104 |
-
sql =
|
| 105 |
-
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)
|
| 106 |
cur = conn.cursor()
|
| 107 |
cur.execute(sql, analysis_data)
|
| 108 |
conn.commit()
|
|
|
|
| 32 |
cursor = conn.cursor()
|
| 33 |
|
| 34 |
# Table to track the source documents (e.g., 'healthy_maize.txt', 'user_guide.pdf')
|
| 35 |
+
cursor.execute("""
|
| 36 |
CREATE TABLE IF NOT EXISTS documents (
|
| 37 |
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 38 |
name TEXT NOT NULL UNIQUE
|
| 39 |
)
|
| 40 |
+
"""
|
| 41 |
)
|
| 42 |
print("Table 'documents' checked/created.")
|
| 43 |
|
| 44 |
# Table to store each chunk of content (text or image)
|
| 45 |
# The faiss_id will correspond to the row number in the FAISS index
|
| 46 |
+
cursor.execute("""
|
| 47 |
CREATE TABLE IF NOT EXISTS chunks (
|
| 48 |
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 49 |
doc_id INTEGER,
|
|
|
|
| 52 |
page_num INTEGER,
|
| 53 |
FOREIGN KEY (doc_id) REFERENCES documents (id)
|
| 54 |
)
|
| 55 |
+
"""
|
| 56 |
)
|
| 57 |
print("Table 'chunks' checked/created.")
|
| 58 |
|
|
|
|
| 101 |
:param analysis_data:
|
| 102 |
:return: project id
|
| 103 |
"""
|
| 104 |
+
sql = """ INSERT INTO farm_analysis(analysis_id,timestamp,farmer_id,gps_latitude,gps_longitude,crop_type,crop_variety,ai_diagnosis,confidence_score,recommended_action,farmer_feedback,treatment_applied,outcome_image_id)
|
| 105 |
+
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?) """
|
| 106 |
cur = conn.cursor()
|
| 107 |
cur.execute(sql, analysis_data)
|
| 108 |
conn.commit()
|