Spaces:
Runtime error
Runtime error
Commit
·
532e36c
1
Parent(s):
f7b5916
Rename app.py0 to app.py
Browse files- app.py0 → app.py +30 -29
app.py0 → app.py
RENAMED
@@ -53,27 +53,28 @@ DB_FILE = "./reviewsitr.db"
|
|
53 |
|
54 |
# Create table if it doesn't already exist
|
55 |
|
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.
|
62 |
-
except sqlite3.OperationalError:
|
63 |
-
db.execute(
|
64 |
-
'''
|
65 |
-
CREATE TABLE reviews (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
66 |
-
created_at TIMESTAMP DEFAULT (datetime('now', 'localtime', '+3 hours')) NOT NULL,
|
67 |
-
name TEXT, view TEXT, duration TEXT)
|
68 |
-
''')
|
69 |
-
db.commit()
|
70 |
-
db.close()
|
71 |
-
|
72 |
-
db = sqlite3.connect(DB_FILE)
|
73 |
# #created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
74 |
-
def get_latest_reviews(db: sqlite3.Connection):
|
75 |
-
reviews = db.execute("SELECT * FROM reviews ORDER BY id DESC limit 100").fetchall()
|
76 |
-
total_reviews = db.execute("Select COUNT(id) from reviews").fetchone()[0]
|
|
|
77 |
reviews = pd.DataFrame(reviews, columns=["id", "date_created", "name", "view", "duration"])
|
78 |
return reviews, total_reviews
|
79 |
|
@@ -84,8 +85,8 @@ def get_latest_reviews2(db: sqlite3.Connection):
|
|
84 |
return reviews2, total_reviews2
|
85 |
|
86 |
def ccogsphere(name: str, rate: int, celsci: str):
|
87 |
-
db = sqlite3.connect(DB_FILE)
|
88 |
-
cursor = db.cursor()
|
89 |
|
90 |
#try:
|
91 |
celsci2=celsci.split()
|
@@ -103,7 +104,7 @@ def ccogsphere(name: str, rate: int, celsci: str):
|
|
103 |
db.commit()
|
104 |
|
105 |
reviews, total_reviews = get_latest_reviews(db)
|
106 |
-
db.close()
|
107 |
r = requests.post(url='https://ccml-persistent-data2.hf.space/api/predict/', json={"data": [celsci + " ", celsci2]})
|
108 |
|
109 |
return reviews, total_reviews
|
@@ -130,27 +131,27 @@ def run_ecs(inp):
|
|
130 |
try:
|
131 |
result=ecf(inp)
|
132 |
df=pd.DataFrame.from_dict(result["videos"])
|
133 |
-
except sqlite3.OperationalError:
|
134 |
print ("db error")
|
135 |
|
136 |
df=df.drop(df.columns[4], axis=1)
|
137 |
|
138 |
-
db = sqlite3.connect(DB_FILE)
|
139 |
#cursor = db.cursor()
|
140 |
#cursor.execute("INSERT INTO reviews2(title, link, thumbnail,channel, description, views, uploaded, duration, durationString) VALUES(?,?,?,?,?,?,?,?,?)", [title, link, thumbnail,channel, description, views, uploaded, duration, durationString])
|
141 |
-
df.to_sql('reviews2', db, if_exists='replace', index=False)
|
142 |
|
143 |
#db.commit()
|
144 |
reviews2, total_reviews2 = get_latest_reviews(db)
|
145 |
-
db.close()
|
146 |
#print ("print000", total_reviews2,reviews2)
|
147 |
return reviews2, total_reviews2
|
148 |
|
149 |
|
150 |
def load_data():
|
151 |
-
db = sqlite3.connect(DB_FILE)
|
152 |
reviews, total_reviews = get_latest_reviews(db)
|
153 |
-
db.close()
|
154 |
return reviews, total_reviews
|
155 |
def load_data2():
|
156 |
db = sqlite3.connect(DB_FILE)
|
@@ -177,7 +178,7 @@ with gr.Blocks(css=css) as demo:
|
|
177 |
demo.load(load_data, None, [data, count])
|
178 |
@name.change(inputs=name, outputs=celsci,_js="window.location.reload()")
|
179 |
@rate.change(inputs=rate, outputs=name,_js="window.location.reload()")
|
180 |
-
|
181 |
|
182 |
def secwork(name):
|
183 |
#if name=="abc":
|
|
|
53 |
|
54 |
# Create table if it doesn't already exist
|
55 |
|
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(
|
64 |
+
# '''
|
65 |
+
# CREATE TABLE reviews (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
66 |
+
# created_at TIMESTAMP DEFAULT (datetime('now', 'localtime', '+3 hours')) NOT NULL,
|
67 |
+
# name TEXT, view TEXT, duration TEXT)
|
68 |
+
# ''')
|
69 |
+
# db.commit()
|
70 |
+
# db.close()
|
71 |
|
72 |
+
# db = sqlite3.connect(DB_FILE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
# #created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
74 |
+
def get_latest_reviews() #db: sqlite3.Connection):
|
75 |
+
#reviews = db.execute("SELECT * FROM reviews ORDER BY id DESC limit 100").fetchall()
|
76 |
+
#total_reviews = db.execute("Select COUNT(id) from reviews").fetchone()[0]
|
77 |
+
total_reviews="N"
|
78 |
reviews = pd.DataFrame(reviews, columns=["id", "date_created", "name", "view", "duration"])
|
79 |
return reviews, total_reviews
|
80 |
|
|
|
85 |
return reviews2, total_reviews2
|
86 |
|
87 |
def ccogsphere(name: str, rate: int, celsci: str):
|
88 |
+
#db = sqlite3.connect(DB_FILE)
|
89 |
+
#cursor = db.cursor()
|
90 |
|
91 |
#try:
|
92 |
celsci2=celsci.split()
|
|
|
104 |
db.commit()
|
105 |
|
106 |
reviews, total_reviews = get_latest_reviews(db)
|
107 |
+
#db.close()
|
108 |
r = requests.post(url='https://ccml-persistent-data2.hf.space/api/predict/', json={"data": [celsci + " ", celsci2]})
|
109 |
|
110 |
return reviews, total_reviews
|
|
|
131 |
try:
|
132 |
result=ecf(inp)
|
133 |
df=pd.DataFrame.from_dict(result["videos"])
|
134 |
+
except: # sqlite3.OperationalError:
|
135 |
print ("db error")
|
136 |
|
137 |
df=df.drop(df.columns[4], axis=1)
|
138 |
|
139 |
+
#db = sqlite3.connect(DB_FILE)
|
140 |
#cursor = db.cursor()
|
141 |
#cursor.execute("INSERT INTO reviews2(title, link, thumbnail,channel, description, views, uploaded, duration, durationString) VALUES(?,?,?,?,?,?,?,?,?)", [title, link, thumbnail,channel, description, views, uploaded, duration, durationString])
|
142 |
+
#df.to_sql('reviews2', db, if_exists='replace', index=False)
|
143 |
|
144 |
#db.commit()
|
145 |
reviews2, total_reviews2 = get_latest_reviews(db)
|
146 |
+
#db.close()
|
147 |
#print ("print000", total_reviews2,reviews2)
|
148 |
return reviews2, total_reviews2
|
149 |
|
150 |
|
151 |
def load_data():
|
152 |
+
#db = sqlite3.connect(DB_FILE)
|
153 |
reviews, total_reviews = get_latest_reviews(db)
|
154 |
+
#db.close()
|
155 |
return reviews, total_reviews
|
156 |
def load_data2():
|
157 |
db = sqlite3.connect(DB_FILE)
|
|
|
178 |
demo.load(load_data, None, [data, count])
|
179 |
@name.change(inputs=name, outputs=celsci,_js="window.location.reload()")
|
180 |
@rate.change(inputs=rate, outputs=name,_js="window.location.reload()")
|
181 |
+
celsci.change(inputs=celsci, outputs=rate,_js="window.location.reload()")
|
182 |
|
183 |
def secwork(name):
|
184 |
#if name=="abc":
|