Spaces:
Runtime error
Runtime error
File size: 3,435 Bytes
e858f86 3fe9033 e858f86 d55bdb6 f178ff7 fcba70b 3fe9033 d55bdb6 60580f0 d55bdb6 |
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 |
import huggingface_hub
import requests
from gradio_client import Client
client = Client("https://cogsphere-acogsphere.hf.space/")
#client = Client("https://cognitivescience-acogspherea.hf.space/--replicas/k5l86/")
#result = client.predict(
# fn_index=1
#)
#print(result)
from python_actr import *
log=log()
class RPSChoice(Model):
choice=None
font='Arial 20'
waiting=True
def start(self):
self.visible=True
self.text=self.instructions
def choose(self,option):
if not self.waiting: return
if option not in ['rock','paper','scissors']: return
self.choice=option
self.visible=False
self.waiting=False
# check to see if both players have made a choice
if self.parent.choice1.choice is not None and self.parent.choice2.choice is not None:
self.parent.determine_winner()
def reset(self):
self.text=self.instructions
self.waiting=True
self.visible=True
self.choice=None
class RockPaperScissors(Model):
choice1=RPSChoice(x=0.5,y=0.2,instructions='Choose: Rock(1) Paper(2) Scissors(3)')
choice2=RPSChoice(x=0.5,y=0.8,instructions='Choose: Rock(Z) Paper(X) Scissors(C)')
result=Model(x=0.5,y=0.5,visible=False)
score1=Model(text=0,x=0.9,y=0.1)
score2=Model(text=0,x=0.9,y=0.9)
trials=0
def key_pressed(self,key):
if key=='1': self.choice1.choose('rock')
if key=='2': self.choice1.choose('paper')
if key=='3': self.choice1.choose('scissors')
if key=='z': self.choice2.choose('rock')
if key=='x': self.choice2.choose('paper')
if key=='c': self.choice2.choose('scissors')
def determine_winner(self):
self.choice1.text=self.choice1.choice
self.choice2.text=self.choice2.choice
self.choice1.visible=True
self.choice2.visible=True
c1=self.choice1.choice
c2=self.choice2.choice
if c1==c2:
self.result.text="Tie!"
elif (c1=='rock' and c2=='scissors') or (c1=='paper' and c2=='rock') or (c1=='scissors' and c2=='paper'):
self.result.text="Player 1 wins!"
self.score1.text+=1
else:
self.result.text="Player 2 wins!"
self.score2.text+=1
self.result.visible=True
yield 1
self.result.visible=False
self.choice1.reset()
self.choice2.reset()
self.trials+=1
if self.trials>=100:
scora=self.score1.text
scorb=self.score2.text
result = client.predict(
"ACT-R RPS"
"100",
"Model 1: " + str(scora) + " Model 2: " + str(scorb),
fn_index=0)
log.score1=self.score1.text
log.score2=self.score2.text
self.stop()
#from ccm.lib.actr import *
class ProceduralPlayer(ACTR):
goal=Buffer()
goal.set('play rps')
def play_rock(goal='play rps',choice='waiting:True'):
choice.choose('rock')
def play_paper(goal='play rps',choice='waiting:True'):
choice.choose('paper')
def play_scissors(goal='play rps',choice='waiting:True'):
choice.choose('scissors')
#env=RockPaperScissors()
#env.model1=ProceduralPlayer()
#env.model1.choice=env.choice1
#env.model2=ProceduralPlayer()
#env.model2.choice=env.choice2
#env.run()
#log_data = env.log
#return log_data[0]['score1'] |