Spaces:
Runtime error
Runtime error
CognitiveScience
commited on
Commit
·
7cffecf
1
Parent(s):
fe493ae
Update app.py
Browse files
app.py
CHANGED
@@ -3,11 +3,15 @@ from bs4 import BeautifulSoup
|
|
3 |
import requests
|
4 |
from acogsphere import acf
|
5 |
from bcogsphere import bcf
|
|
|
|
|
|
|
6 |
import math
|
|
|
7 |
|
8 |
import sqlite3
|
9 |
import huggingface_hub
|
10 |
-
import pandas as pd
|
11 |
import shutil
|
12 |
import os
|
13 |
import datetime
|
@@ -15,7 +19,7 @@ from apscheduler.schedulers.background import BackgroundScheduler
|
|
15 |
|
16 |
import random
|
17 |
import time
|
18 |
-
import requests
|
19 |
|
20 |
from huggingface_hub import hf_hub_download
|
21 |
|
@@ -52,6 +56,8 @@ repo.git_pull()
|
|
52 |
db = sqlite3.connect(DB_FILE)
|
53 |
try:
|
54 |
db.execute("SELECT * FROM reviews").fetchall()
|
|
|
|
|
55 |
db.close()
|
56 |
except sqlite3.OperationalError:
|
57 |
db.execute(
|
@@ -63,17 +69,47 @@ except sqlite3.OperationalError:
|
|
63 |
db.commit()
|
64 |
db.close()
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
def get_latest_reviews(db: sqlite3.Connection):
|
67 |
reviews = db.execute("SELECT * FROM reviews ORDER BY id DESC limit 100").fetchall()
|
68 |
total_reviews = db.execute("Select COUNT(id) from reviews").fetchone()[0]
|
69 |
reviews = pd.DataFrame(reviews, columns=["id", "date_created", "name", "rate", "celsci"])
|
70 |
return reviews, total_reviews
|
71 |
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
73 |
def ccogsphere(name: str, rate: int, celsci: str):
|
74 |
db = sqlite3.connect(DB_FILE)
|
75 |
cursor = db.cursor()
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
db.commit()
|
78 |
reviews, total_reviews = get_latest_reviews(db)
|
79 |
db.close()
|
@@ -99,17 +135,42 @@ def run_actr():
|
|
99 |
env.model2.choice=env.choice2
|
100 |
env.run()
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
def load_data():
|
104 |
db = sqlite3.connect(DB_FILE)
|
105 |
reviews, total_reviews = get_latest_reviews(db)
|
106 |
db.close()
|
107 |
return reviews, total_reviews
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
css="footer {visibility: hidden}"
|
110 |
# Applying style to highlight the maximum value in each row
|
111 |
#styler = df.style.highlight_max(color = 'lightgreen', axis = 0)
|
112 |
-
with gr.Blocks(
|
113 |
with gr.Row():
|
114 |
with gr.Column():
|
115 |
data = gr.Dataframe() #styler)
|
@@ -120,7 +181,7 @@ with gr.Blocks(css=css) as demo:
|
|
120 |
rate = gr.Textbox(label="b") #, placeholder="What is your name?") #gr.Radio(label="How satisfied are you with using gradio?", choices=[1, 2, 3, 4, 5])
|
121 |
celsci = gr.Textbox(label="c") #, lines=10, placeholder="Do you have any feedback on gradio?")
|
122 |
#run_actr()
|
123 |
-
submit = gr.Button(value=".")
|
124 |
submit.click(ccogsphere, [name, rate, celsci], [data, count])
|
125 |
demo.load(load_data, None, [data, count])
|
126 |
@name.change(inputs=name, outputs=celsci,_js="window.location.reload()")
|
@@ -163,9 +224,9 @@ def backup_db_csv():
|
|
163 |
# demo.load(load_data,None, [reviews, total_reviews])
|
164 |
# #return reviews, total_reviews
|
165 |
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
|
170 |
scheduler2 = BackgroundScheduler()
|
171 |
scheduler2.add_job(func=backup_db, trigger="interval", seconds=3633000)
|
|
|
3 |
import requests
|
4 |
from acogsphere import acf
|
5 |
from bcogsphere import bcf
|
6 |
+
from ecogsphere import ecf
|
7 |
+
|
8 |
+
import pandas as pd
|
9 |
import math
|
10 |
+
import json
|
11 |
|
12 |
import sqlite3
|
13 |
import huggingface_hub
|
14 |
+
#import pandas as pd
|
15 |
import shutil
|
16 |
import os
|
17 |
import datetime
|
|
|
19 |
|
20 |
import random
|
21 |
import time
|
22 |
+
#import requests
|
23 |
|
24 |
from huggingface_hub import hf_hub_download
|
25 |
|
|
|
56 |
db = sqlite3.connect(DB_FILE)
|
57 |
try:
|
58 |
db.execute("SELECT * FROM reviews").fetchall()
|
59 |
+
#db.execute("SELECT * FROM reviews2").fetchall()
|
60 |
+
|
61 |
db.close()
|
62 |
except sqlite3.OperationalError:
|
63 |
db.execute(
|
|
|
69 |
db.commit()
|
70 |
db.close()
|
71 |
|
72 |
+
db = sqlite3.connect(DB_FILE)
|
73 |
+
try:
|
74 |
+
db.execute("SELECT * FROM reviews2").fetchall()
|
75 |
+
#db.execute("SELECT * FROM reviews2").fetchall()
|
76 |
+
|
77 |
+
db.close()
|
78 |
+
except sqlite3.OperationalError:
|
79 |
+
db.execute(
|
80 |
+
'''
|
81 |
+
CREATE TABLE reviews2 (id TEXT,
|
82 |
+
title TEXT, link TEXT,channel TEXT, description TEXT, views INTEGER, uploaded TEXT, duration INTEGER, durationString TEXT)
|
83 |
+
''')
|
84 |
+
db.commit()
|
85 |
+
db.close()
|
86 |
def get_latest_reviews(db: sqlite3.Connection):
|
87 |
reviews = db.execute("SELECT * FROM reviews ORDER BY id DESC limit 100").fetchall()
|
88 |
total_reviews = db.execute("Select COUNT(id) from reviews").fetchone()[0]
|
89 |
reviews = pd.DataFrame(reviews, columns=["id", "date_created", "name", "rate", "celsci"])
|
90 |
return reviews, total_reviews
|
91 |
|
92 |
+
def get_latest_reviews2(db: sqlite3.Connection):
|
93 |
+
reviews2 = db.execute("SELECT * FROM reviews2 ORDER BY id DESC limit 100").fetchall()
|
94 |
+
total_reviews2 = db.execute("Select COUNT(id) from reviews2").fetchone()[0]
|
95 |
+
reviews2 = pd.DataFrame(reviews2, columns=["id","title", "link","channel", "description", "views", "uploaded", "duration", "durationString"])
|
96 |
+
return reviews2, total_reviews2
|
97 |
+
|
98 |
def ccogsphere(name: str, rate: int, celsci: str):
|
99 |
db = sqlite3.connect(DB_FILE)
|
100 |
cursor = db.cursor()
|
101 |
+
|
102 |
+
try:
|
103 |
+
celsci2=celsci.split()
|
104 |
+
print("split",celsci2,celsci)
|
105 |
+
celsci2=celsci2[0] + "+" + celsci2[1]
|
106 |
+
celsci2=ecf(celsci2)
|
107 |
+
celsci2=json.dumps(celsci2["videos"])
|
108 |
+
except:
|
109 |
+
celsci2=" No Info Found"
|
110 |
+
|
111 |
+
|
112 |
+
cursor.execute("INSERT INTO reviews(name, rate, celsci) VALUES(?,?,?)", [name, rate, celsci+celsci2])
|
113 |
db.commit()
|
114 |
reviews, total_reviews = get_latest_reviews(db)
|
115 |
db.close()
|
|
|
135 |
env.model2.choice=env.choice2
|
136 |
env.run()
|
137 |
|
138 |
+
def run_ecs(inp):
|
139 |
+
try:
|
140 |
+
result=ecf(inp)
|
141 |
+
df=pd.DataFrame.from_dict(result["videos"])
|
142 |
+
except sqlite3.OperationalError:
|
143 |
+
print ("db error")
|
144 |
+
|
145 |
+
df=df.drop(df.columns[4], axis=1)
|
146 |
+
|
147 |
+
db = sqlite3.connect(DB_FILE)
|
148 |
+
#cursor = db.cursor()
|
149 |
+
#cursor.execute("INSERT INTO reviews2(title, link, thumbnail,channel, description, views, uploaded, duration, durationString) VALUES(?,?,?,?,?,?,?,?,?)", [title, link, thumbnail,channel, description, views, uploaded, duration, durationString])
|
150 |
+
df.to_sql('reviews2', db, if_exists='replace', index=False)
|
151 |
+
|
152 |
+
#db.commit()
|
153 |
+
reviews2, total_reviews2 = get_latest_reviews(db)
|
154 |
+
db.close()
|
155 |
+
#print ("print000", total_reviews2,reviews2)
|
156 |
+
return reviews2, total_reviews2
|
157 |
+
|
158 |
|
159 |
def load_data():
|
160 |
db = sqlite3.connect(DB_FILE)
|
161 |
reviews, total_reviews = get_latest_reviews(db)
|
162 |
db.close()
|
163 |
return reviews, total_reviews
|
164 |
+
def load_data2():
|
165 |
+
db = sqlite3.connect(DB_FILE)
|
166 |
+
reviews2, total_reviews2 = get_latest_reviews2(db)
|
167 |
+
db.close()
|
168 |
+
return reviews2, total_reviews2
|
169 |
|
170 |
css="footer {visibility: hidden}"
|
171 |
# Applying style to highlight the maximum value in each row
|
172 |
#styler = df.style.highlight_max(color = 'lightgreen', axis = 0)
|
173 |
+
with gr.Blocks() as demo:
|
174 |
with gr.Row():
|
175 |
with gr.Column():
|
176 |
data = gr.Dataframe() #styler)
|
|
|
181 |
rate = gr.Textbox(label="b") #, placeholder="What is your name?") #gr.Radio(label="How satisfied are you with using gradio?", choices=[1, 2, 3, 4, 5])
|
182 |
celsci = gr.Textbox(label="c") #, lines=10, placeholder="Do you have any feedback on gradio?")
|
183 |
#run_actr()
|
184 |
+
submit = gr.Button(value=".")
|
185 |
submit.click(ccogsphere, [name, rate, celsci], [data, count])
|
186 |
demo.load(load_data, None, [data, count])
|
187 |
@name.change(inputs=name, outputs=celsci,_js="window.location.reload()")
|
|
|
224 |
# demo.load(load_data,None, [reviews, total_reviews])
|
225 |
# #return reviews, total_reviews
|
226 |
|
227 |
+
scheduler1 = BackgroundScheduler()
|
228 |
+
scheduler1.add_job(func=run_actr, trigger="interval", seconds=36)
|
229 |
+
scheduler1.start()
|
230 |
|
231 |
scheduler2 = BackgroundScheduler()
|
232 |
scheduler2.add_job(func=backup_db, trigger="interval", seconds=3633000)
|