Spaces:
Runtime error
Runtime error
mertcobanov
commited on
Commit
•
dbb1743
1
Parent(s):
3659660
added done state
Browse files- .gitignore +2 -0
- app.py +11 -1
- db_utils.py +39 -0
.gitignore
CHANGED
@@ -158,3 +158,5 @@ cython_debug/
|
|
158 |
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
159 |
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
160 |
#.idea/
|
|
|
|
|
|
158 |
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
159 |
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
160 |
#.idea/
|
161 |
+
|
162 |
+
.DS_Store
|
app.py
CHANGED
@@ -30,6 +30,14 @@ def get_parsed_address(input_img):
|
|
30 |
def save_deta_db(input):
|
31 |
eval_result = ast.literal_eval(input)
|
32 |
utils.write_db(eval_result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
# Open API on change
|
34 |
def text_dict(input):
|
35 |
eval_result = ast.literal_eval(input)
|
@@ -140,7 +148,9 @@ with gr.Blocks() as demo:
|
|
140 |
)
|
141 |
|
142 |
submit_button = gr.Button(value="Veriyi Birimlere Yolla")
|
143 |
-
submit_button.click(save_deta_db, open_api_text)
|
|
|
|
|
144 |
|
145 |
if __name__ == "__main__":
|
146 |
demo.launch()
|
|
|
30 |
def save_deta_db(input):
|
31 |
eval_result = ast.literal_eval(input)
|
32 |
utils.write_db(eval_result)
|
33 |
+
return
|
34 |
+
|
35 |
+
def update_component():
|
36 |
+
return gr.update(value='Gonderildi, lutfen sayfayi yenileyin.', visible=True)
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
# Open API on change
|
42 |
def text_dict(input):
|
43 |
eval_result = ast.literal_eval(input)
|
|
|
148 |
)
|
149 |
|
150 |
submit_button = gr.Button(value="Veriyi Birimlere Yolla")
|
151 |
+
# submit_button.click(save_deta_db, open_api_text)
|
152 |
+
done_text = gr.Textbox(label='Done', value='Not Done', visible=False)
|
153 |
+
submit_button.click(update_component, outputs=done_text)
|
154 |
|
155 |
if __name__ == "__main__":
|
156 |
demo.launch()
|
db_utils.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from deta import Deta # Import Deta
|
2 |
+
from pprint import pprint
|
3 |
+
import os
|
4 |
+
|
5 |
+
deta_key = os.getenv("DETA_KEY")
|
6 |
+
deta = Deta(deta_key)
|
7 |
+
db = deta.Base("deprem-ocr")
|
8 |
+
|
9 |
+
def get_users_by_city(city_name, limit=10):
|
10 |
+
|
11 |
+
user = db.fetch({"city": city_name.capitalize()}, limit=limit).items
|
12 |
+
return user
|
13 |
+
|
14 |
+
|
15 |
+
def get_all():
|
16 |
+
res = db.fetch()
|
17 |
+
all_items = res.items
|
18 |
+
|
19 |
+
# fetch until last is 'None'
|
20 |
+
while res.last:
|
21 |
+
res = db.fetch(last=res.last)
|
22 |
+
all_items += res.items
|
23 |
+
return all_items
|
24 |
+
|
25 |
+
|
26 |
+
def write_db(data_dict):
|
27 |
+
# 2) initialize with a project key
|
28 |
+
deta_key = os.getenv("DETA_KEY")
|
29 |
+
deta = Deta(deta_key)
|
30 |
+
|
31 |
+
# 3) create and use as many DBs as you want!
|
32 |
+
users = deta.Base("deprem-ocr")
|
33 |
+
users.insert(data_dict)
|
34 |
+
print('Pushed to db')
|
35 |
+
|
36 |
+
def get_latest_row(last):
|
37 |
+
all_items = get_all()
|
38 |
+
latest_items = all_items[-last:]
|
39 |
+
return latest_items
|