Spaces:
Runtime error
Runtime error
CognitiveScience
commited on
Commit
·
8828ef5
1
Parent(s):
92a037f
Update app.py
Browse files
app.py
CHANGED
@@ -4,20 +4,7 @@ import requests
|
|
4 |
from acogsphere import acf
|
5 |
from bcogsphere import bcf
|
6 |
import math
|
7 |
-
import
|
8 |
-
#from python_actr import *
|
9 |
-
#from cogscidighum import *
|
10 |
-
|
11 |
-
|
12 |
-
#class myCelSci(Model):
|
13 |
-
# pass
|
14 |
-
|
15 |
-
#def main(link):
|
16 |
-
# response=getviews(link)+getresult("hello world")[0]["label"] + str(math.trunc(getresult("hello world")[0]["score"])*100/100)
|
17 |
-
# return response #result #soup.prettify()
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
import sqlite3
|
22 |
import huggingface_hub
|
23 |
import pandas as pd
|
@@ -60,7 +47,6 @@ except sqlite3.OperationalError:
|
|
60 |
db.commit()
|
61 |
db.close()
|
62 |
|
63 |
-
|
64 |
def get_latest_reviews(db: sqlite3.Connection):
|
65 |
reviews = db.execute("SELECT * FROM reviews ORDER BY id DESC limit 10").fetchall()
|
66 |
total_reviews = db.execute("Select COUNT(id) from reviews").fetchone()[0]
|
@@ -82,34 +68,6 @@ def load_data():
|
|
82 |
reviews, total_reviews = get_latest_reviews(db)
|
83 |
db.close()
|
84 |
return reviews, total_reviews
|
85 |
-
|
86 |
-
def delete_review(id: int):
|
87 |
-
db = sqlite3.connect(DB_FILE)
|
88 |
-
cursor = db.cursor()
|
89 |
-
cursor.execute("DELETE FROM reviews WHERE id = ?", [id])
|
90 |
-
db.commit()
|
91 |
-
reviews, total_reviews = get_latest_reviews(db)
|
92 |
-
db.close()
|
93 |
-
return reviews, total_reviews
|
94 |
-
|
95 |
-
def delete_all_reviews():
|
96 |
-
db = sqlite3.connect(DB_FILE)
|
97 |
-
cursor = db.cursor()
|
98 |
-
cursor.execute("DELETE FROM reviews")
|
99 |
-
db.commit()
|
100 |
-
reviews, total_reviews = get_latest_reviews(db)
|
101 |
-
db.close()
|
102 |
-
return reviews, total_reviews
|
103 |
-
#def cs(link):
|
104 |
-
# response="Hi " + "bcf" #(link) #acf("hello world")[0]["label"] + str(math.trunc(acf("hello world")[0]["score"])*100/100)+bcf(link)
|
105 |
-
# return response #result #soup.prettify()
|
106 |
-
|
107 |
-
def respond3(message, chat_history):
|
108 |
-
bot_message = random.choice(["How are you3?", "I love you3", "I'm very hungry3"])
|
109 |
-
chat_history.append((message, bot_message))
|
110 |
-
time.sleep(2)
|
111 |
-
|
112 |
-
return "", chat_history
|
113 |
|
114 |
with gr.Blocks() as demo:
|
115 |
with gr.Row():
|
@@ -123,39 +81,10 @@ with gr.Blocks() as demo:
|
|
123 |
review = gr.Radio(label="How satisfied are you with using gradio?", choices=[1, 2, 3, 4, 5])
|
124 |
comments = gr.Textbox(label="Comments", lines=10, placeholder="Do you have any feedback on gradio?")
|
125 |
submit = gr.Button(value="Submit Feedback")
|
126 |
-
with gr.Row():
|
127 |
-
with gr.Column():
|
128 |
-
chatbot = gr.Chatbot()
|
129 |
-
msg = gr.Textbox()
|
130 |
-
clear = gr.ClearButton([msg, chatbot])
|
131 |
-
|
132 |
-
def respond(message, chat_history):
|
133 |
-
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
134 |
-
chat_history.append((message, bot_message))
|
135 |
-
time.sleep(2)
|
136 |
-
|
137 |
-
return "", chat_history
|
138 |
-
|
139 |
-
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
140 |
|
141 |
submit.click(add_review, [name, review, comments], [data, count])
|
142 |
-
|
143 |
-
#cssubmit.click(add_review, [name, review, comments], [data, count])
|
144 |
-
|
145 |
-
#record2del = gr.Textbox(label="Id: ", lines=1, placeholder="to delete?")
|
146 |
-
|
147 |
-
#submit2 = gr.Button(value="Delete Review")
|
148 |
-
#id_input = gr.Number(value=202, visible=False)
|
149 |
-
#submit2.click(delete_review, id_input)
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
#submit3 = gr.Button(value="Delete All Reviews")
|
154 |
-
#submit3.click(delete_all_reviews)
|
155 |
-
|
156 |
-
|
157 |
demo.load(load_data, None, [data, count])
|
158 |
-
|
159 |
def backup_db():
|
160 |
shutil.copyfile(DB_FILE, "./data/reviews.db")
|
161 |
db = sqlite3.connect(DB_FILE)
|
@@ -164,10 +93,7 @@ def backup_db():
|
|
164 |
print("updating db")
|
165 |
repo.push_to_hub(blocking=False, commit_message=f"Updating data at {datetime.datetime.now()}")
|
166 |
|
167 |
-
|
168 |
scheduler = BackgroundScheduler()
|
169 |
scheduler.add_job(func=backup_db, trigger="interval", seconds=60)
|
170 |
scheduler.start()
|
171 |
-
|
172 |
-
|
173 |
demo.launch()
|
|
|
4 |
from acogsphere import acf
|
5 |
from bcogsphere import bcf
|
6 |
import math
|
7 |
+
import glo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
import sqlite3
|
9 |
import huggingface_hub
|
10 |
import pandas as pd
|
|
|
47 |
db.commit()
|
48 |
db.close()
|
49 |
|
|
|
50 |
def get_latest_reviews(db: sqlite3.Connection):
|
51 |
reviews = db.execute("SELECT * FROM reviews ORDER BY id DESC limit 10").fetchall()
|
52 |
total_reviews = db.execute("Select COUNT(id) from reviews").fetchone()[0]
|
|
|
68 |
reviews, total_reviews = get_latest_reviews(db)
|
69 |
db.close()
|
70 |
return reviews, total_reviews
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
with gr.Blocks() as demo:
|
73 |
with gr.Row():
|
|
|
81 |
review = gr.Radio(label="How satisfied are you with using gradio?", choices=[1, 2, 3, 4, 5])
|
82 |
comments = gr.Textbox(label="Comments", lines=10, placeholder="Do you have any feedback on gradio?")
|
83 |
submit = gr.Button(value="Submit Feedback")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
submit.click(add_review, [name, review, comments], [data, count])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
demo.load(load_data, None, [data, count])
|
87 |
+
|
88 |
def backup_db():
|
89 |
shutil.copyfile(DB_FILE, "./data/reviews.db")
|
90 |
db = sqlite3.connect(DB_FILE)
|
|
|
93 |
print("updating db")
|
94 |
repo.push_to_hub(blocking=False, commit_message=f"Updating data at {datetime.datetime.now()}")
|
95 |
|
|
|
96 |
scheduler = BackgroundScheduler()
|
97 |
scheduler.add_job(func=backup_db, trigger="interval", seconds=60)
|
98 |
scheduler.start()
|
|
|
|
|
99 |
demo.launch()
|