Spaces:
Runtime error
Runtime error
File size: 7,648 Bytes
4fe8a03 f07a76e 388bced 4fe8a03 388bced f3f2130 4fe8a03 e4b743f 78ed805 da68b17 e9a8ede fb6ebd2 e9a8ede 4fe8a03 bf86616 4fe8a03 f07a76e 341a79f 4e5aa69 4fe8a03 eb695d4 c877caa 58d82ec c652a61 e9a8ede 4fe8a03 e9a8ede 4fe8a03 b72bc42 4fe8a03 03e689c 4fe8a03 b934676 4fe8a03 b72bc42 4fe8a03 b934676 4fe8a03 77001b5 54725b9 4fe8a03 07170ba 039819f f07a76e 388bced c3a56cd a4920f4 b764f3e a4920f4 092e1e6 a4920f4 b764f3e 2326dd2 b764f3e f07a76e 4fe8a03 7815235 25be80a 7815235 e74f020 ea94c7e c1b0716 71d3467 4fe8a03 a297e9a 2326dd2 25be80a 4d4b545 bb4e5fc 4d4b545 a4920f4 bb4e5fc 7815235 388bced 741cfba 7815235 344e7b1 b7956c7 8cafaa1 6b5276f 89f00b4 8cafaa1 774449d 13c256e fdebc5f 7ef424f 4fe8a03 bf86616 4fe8a03 bf86616 4fe8a03 e9a8ede bf86616 e9a8ede bf86616 e9a8ede bf86616 0759b36 e5a7845 0136bd4 8d3471b 2e45868 770c900 954e78c 039819f f07a76e b2f154f f07a76e bb4e5fc 4eba62e bb4e5fc 4024d85 bb4e5fc e9a8ede 0d6dac3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
import gradio as gr
from bs4 import BeautifulSoup
import requests
from acogsphere import acf
from bcogsphere import bcf
from ecogsphere import ecf
import pandas as pd
import math
import json
import sqlite3
import huggingface_hub
import pandas as pd
import shutil
import os
import datetime
from apscheduler.schedulers.background import BackgroundScheduler
import random
import time
import requests
from huggingface_hub import hf_hub_download
#hf_hub_download(repo_id="CogSphere/aCogSphere", filename="./reviews.csv")
from huggingface_hub import login
from datasets import load_dataset
#dataset = load_dataset("csv", data_files="./data.csv")
DB_FILE = "./reviewsE.db"
#TOKEN = os.environ.get('HF_KEY')
#TOKEN=os.environ.get('RA_TOKEN')
#print (TOKEN[-1])
#TOKEN2 = HF_TOKEN
#repo = huggingface_hub.Repository(
# local_dir="data",
# repo_type="dataset",
# clone_from="CognitiveScience/csdhdata",
# use_auth_token=TOKEN
#)
#repo.git_pull()
#login(token=TOKEN2)
# Set db to latest
#shutil.copyfile("./data/reviews01.db", DB_FILE)
# Create table if it doesn't already exist
db = sqlite3.connect(DB_FILE)
try:
db.execute("SELECT * FROM reviews").fetchall()
db.close()
except sqlite3.OperationalError:
db.execute(
'''
CREATE TABLE reviews (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
name TEXT, rate INTEGER, celsci TEXT)
''')
db.commit()
db.close()
def get_latest_reviews(db: sqlite3.Connection):
reviews = db.execute("SELECT * FROM reviews ORDER BY id DESC limit 100").fetchall()
total_reviews = db.execute("Select COUNT(id) from reviews").fetchone()[0]
reviews = pd.DataFrame(reviews, columns=["id", "date_created", "name", "rate", "celsci"])
return reviews, total_reviews
def ccogsphere(name: str, rate: int, celsci: str):
db = sqlite3.connect(DB_FILE)
cursor = db.cursor()
cursor.execute("INSERT INTO reviews(name, rate, celsci) VALUES(?,?,?)", [name, rate, celsci])
db.commit()
reviews, total_reviews = get_latest_reviews(db)
db.close()
r = requests.post(url='https://ccml-persistent-data2.hf.space/api/predict/', json={"data": [name,celsci]})
#demo.load()
return reviews, total_reviews
def run_actr():
from python_actr import log_everything
#code1="tim = MyAgent()"
#code2="subway=MyEnv()"
#code3="subway.agent=tim"
#code4="log_everything(subway)"]
from dcogsphere import RockPaperScissors
from dcogsphere import ProceduralPlayer
#from dcogsphere import logy
env=RockPaperScissors()
env.model1=ProceduralPlayer()
env.model1.choice=env.choice1
env.model2=ProceduralPlayer()
env.model2.choice=env.choice2
env.run()
def run_ecs(inp):
#result=ecf(inp)
#db = sqlite3.connect(DB_FILE)
try:
result=ecf(inp)
#db.execute("SELECT * FROM reviews").fetchall()
#reviews = pd.DataFrame(reviews, columns=["id", "date_created", "name", "rate", "celsci"])
#reviews, total_reviews = get_latest_reviews(db)
print(result)
except sqlite3.OperationalError:
print ("db error")
return result
def load_data():
db = sqlite3.connect(DB_FILE)
reviews, total_reviews = get_latest_reviews(db)
db.close()
return reviews, total_reviews
# Creating a sample dataframe
#df = pd.DataFrame({
# "A" : [14, 4, 5, 4, 1],
# "B" : [5, 2, 54, 3, 2],
# "C" : [20, 20, 7, 3, 8],
# "D" : [14, 3, 6, 2, 6],
# "E" : [23, 45, 64, 32, 23]
#})
# Applying style to highlight the maximum value in each row
css="footer {visibility: hidden}"
# Applying style to highlight the maximum value in each row
#styler = df.style.highlight_max(color = 'lightgreen', axis = 0)
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
#result=run_ecs("Dan")
celscie = gr.Textbox(label="e",value="robert+west") #, placeholder="What is your name?")
#submite = gr.Button(value="E")
#submite.click(ecs, [name, rate, celsci], [data, count])
df=run_ecs(celscie)
#df=pd.DataFrame(result)
#styler = df.style.highlight_max(color = 'lightgreen', axis = 0)
#styl = df.style.apply(highlight_cols, axis = None)
#print(result)
gr.Dataframe(df)
#df1=run_ecs("Dan")
#df1=json.loads(js1)
#data = gr.Dataframe(styler)
#count = gr.Number(label="Rates!")
with gr.Row():
with gr.Column():
data = gr.Dataframe() #styler)
count = gr.Number(label="Rates!")
with gr.Row():
with gr.Column():
name = gr.Textbox(label="a") #, placeholder="What is your name?")
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])
celsci = gr.Textbox(label="c") #, lines=10, placeholder="Do you have any feedback on gradio?")
#run_actr()
submit = gr.Button(value=".")
submit.click(ccogsphere, [name, rate, celsci], [data, count])
demo.load(load_data, None, [data, count])
@name.change(inputs=name, outputs=celsci,_js="window.location.reload()")
@rate.change(inputs=rate, outputs=name,_js="window.location.reload()")
@celsci.change(inputs=celsci, outputs=rate,_js="window.location.reload()")
def secwork(name):
#if name=="abc":
#run_code()
load_data()
#return "Hello " + name + "!"
def backup_db():
shutil.copyfile(DB_FILE, "./reviews1E.db")
db = sqlite3.connect(DB_FILE)
reviews = db.execute("SELECT * FROM reviews").fetchall()
pd.DataFrame(reviews).to_csv("./reviewsE.csv", index=False)
print("updating db")
repo.push_to_hub(blocking=False, commit_message=f"Updating data at {datetime.datetime.now()}")
def backup_db_csv():
shutil.copyfile(DB_FILE, "./reviews2E.db")
db = sqlite3.connect(DB_FILE)
reviews = db.execute("SELECT * FROM reviews").fetchall()
pd.DataFrame(reviews).to_csv("./reviews2E.csv", index=False)
print("updating db csv")
dataset = load_dataset("csv", data_files="./reviews2E.csv")
repo.push_to_hub("CognitiveScience/csdhdata", blocking=False) #, commit_message=f"Updating data-csv at {datetime.datetime.now()}")
#path1=hf_hub_url()
#print (path1)
#hf_hub_download(repo_id="CogSphere/aCogSphere", filename="./*.csv")
#hf_hub_download(repo_id="CognitiveScience/csdhdata", filename="./*.db")
#hf_hub_download(repo_id="CogSphere/aCogSphere", filename="./*.md")
#hf_hub_download(repo_id="CognitiveScience/csdhdata", filename="./*.md")
#def load_data2():
# db = sqlite3.connect(DB_FILE)
# reviews, total_reviews = get_latest_reviews(db)
# #db.close()
# demo.load(load_data,None, [reviews, total_reviews])
# #return reviews, total_reviews
#scheduler0 = BackgroundScheduler()
#scheduler0.add_job(func=run_ecs, trigger="interval", seconds=180000)
#scheduler0.start()
#scheduler1 = BackgroundScheduler()
#scheduler1.add_job(func=run_actr, trigger="interval", seconds=3600)
#scheduler1.start()
#scheduler2 = BackgroundScheduler()
#scheduler2.add_job(func=backup_db, trigger="interval", seconds=3633000)
#scheduler2.start()
#scheduler3 = BackgroundScheduler()
#scheduler3.add_job(func=backup_db_csv, trigger="interval", seconds=3666000)
#scheduler3.start()
demo.launch() |