CognitiveScience commited on
Commit
31695fc
1 Parent(s): 9562d14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -9
app.py CHANGED
@@ -74,10 +74,17 @@ from datasets import load_dataset
74
 
75
  # db = sqlite3.connect(DB_FILE)
76
  # #created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
77
- def get_latest_reviews(): #db: sqlite3.Connection):
 
 
 
 
 
 
 
 
78
  #reviews = db.execute("SELECT * FROM reviews ORDER BY id DESC limit 100").fetchall()
79
  #total_reviews = db.execute("Select COUNT(id) from reviews").fetchone()[0]
80
- reviews = reviews.DataFrame(reviews, columns=["id", "date_created", "name", "view", "duration"])
81
  total_reviews=reviews.count()[0]
82
  return reviews, total_reviews
83
 
@@ -136,7 +143,8 @@ def run_ecs(inp):
136
  result=ecf(inp)
137
  df=pd.DataFrame.from_dict(result["videos"])
138
  except: # sqlite3.OperationalError:
139
- print ("db error")
 
140
 
141
  #df=df.drop(df.columns[4], axis=1)
142
 
@@ -149,6 +157,9 @@ def run_ecs(inp):
149
  #reviews2, total_reviews2 = get_latest_reviews(db)
150
  #db.close()
151
  #print ("print000", total_reviews2,reviews2)
 
 
 
152
  return reviews2, total_reviews2
153
 
154
 
@@ -179,15 +190,15 @@ with gr.Blocks(css=css) as demo:
179
  #run_actr()
180
  submit = gr.Button(value=".")
181
  submit.click(ccogsphere, [name, rate, celsci], [data, count])
182
- demo.load(load_data, None, [data, count])
183
- #@name.change(inputs=name, outputs=celsci,_js="window.location.reload()")
184
- #@rate.change(inputs=rate, outputs=name,_js="window.location.reload()")
185
- @celsci.change(inputs=celsci, outputs=rate,_js="window.location.reload()")
186
 
187
- def secwork(name):
188
  #if name=="abc":
189
  #run_code()
190
- get_latest_reviews()
191
  #return "Hello " + name + "!"
192
  def backup_db():
193
  #shutil.copyfile(DB_FILE, "./reviews.db")
 
74
 
75
  # db = sqlite3.connect(DB_FILE)
76
  # #created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
77
+ def get_latest_reviews(celsci2): #db: sqlite3.Connection):
78
+ try:
79
+ celsci2=ecf(celsci2)
80
+ df=pd.DataFrame.from_dict(celsci2["videos"])
81
+ reviews = df.DataFrame(reviews, columns=["id", "date_created", "name", "view", "duration"])
82
+
83
+ except: # sqlite3.OperationalError:
84
+ df=pd.DataFrame()
85
+ print ("db ...")
86
  #reviews = db.execute("SELECT * FROM reviews ORDER BY id DESC limit 100").fetchall()
87
  #total_reviews = db.execute("Select COUNT(id) from reviews").fetchone()[0]
 
88
  total_reviews=reviews.count()[0]
89
  return reviews, total_reviews
90
 
 
143
  result=ecf(inp)
144
  df=pd.DataFrame.from_dict(result["videos"])
145
  except: # sqlite3.OperationalError:
146
+ df=pd.DataFrame()
147
+ print ("db ...")
148
 
149
  #df=df.drop(df.columns[4], axis=1)
150
 
 
157
  #reviews2, total_reviews2 = get_latest_reviews(db)
158
  #db.close()
159
  #print ("print000", total_reviews2,reviews2)
160
+ reviews2=df
161
+ total_reviews2=reviews2.count()[0]
162
+
163
  return reviews2, total_reviews2
164
 
165
 
 
190
  #run_actr()
191
  submit = gr.Button(value=".")
192
  submit.click(ccogsphere, [name, rate, celsci], [data, count])
193
+ demo.load(get_latest_reviews, celsci, [data, count])
194
+ @name.change(inputs=name, outputs=celsci,_js="window.location.reload()")
195
+ @rate.change(inputs=rate, outputs=name,_js="window.location.reload()")
196
+ #@celsci.change(inputs=celsci, outputs=rate,_js="window.location.reload()")
197
 
198
+ def secwork(celsci):
199
  #if name=="abc":
200
  #run_code()
201
+ demo.load(get_latest_reviews, celsci, [data, count])
202
  #return "Hello " + name + "!"
203
  def backup_db():
204
  #shutil.copyfile(DB_FILE, "./reviews.db")