Spaces:
Runtime error
Runtime error
File size: 2,454 Bytes
5bdee70 1415823 a50f406 1415823 5bdee70 229c087 5bdee70 117fa11 b6f9391 117fa11 b6f9391 117fa11 7ec4c55 b607857 42c813a 0082761 4ca8044 b1e8f80 5ae7b47 5eb0598 b6f9391 1cf90bc 5bdee70 50d2f67 5bdee70 f474895 5bdee70 50d2f67 5bdee70 117fa11 5bdee70 |
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 |
import streamlit as st
from model import GeneralModel
import os
import chess
import chess.engine
import stat
import re
def app():
# Creating an object of prediction service
pred = GeneralModel()
api_key = st.sidebar.text_input("APIkey get it here https://beta.openai.com/account/api-keys", type="password")
# Using the streamlit cache
@st.cache
def eval(fenstring):
output = ""
os.chmod("./stockfish_14_x64_popcnt",0o0777)
engine = chess.engine.SimpleEngine.popen_uci("./stockfish_14_x64_popcnt")
# Score: PovScore(Cp(+20), WHITE)
board = chess.Board(fenstring)
info = engine.analyse(board, chess.engine.Limit(depth=20),multipv=3)
# Score: PovScore(Mate(+1), WHITE)
engine.quit()
evalstring = str(info)
print (evalstring)
#hacky way to parse best move, need to imprpve
substrings = evalstring.split('Move.from_uci')
# Extract the text between the single quotes using a regular expression
match = re.search(r"'(.*?)'", substrings[1])
topmove = match.group(1)
print(topmove)
# Create a list of lists, where each inner list contains the UCI strings for a single move
stringprompt = 'Based on the chess board position at this fen string ' + fenstring + 'can you give an in depth analysis as to why ' + topmove + ' is the best move to play based on Material, Development, Center-control, King-safety and Pawn-structures if relevant. Also describe any tactics or ideas that we should be thinking about'
return pred.model_prediction(input=stringprompt.strip() , api_key=api_key)
def process_prompt(input):
return pred.model_prediction(input=input.strip() , api_key=api_key)
if api_key:
# Setting up the Title
st.title("Stockfish fen eval to GPT-3 top move explanation chess coach")
# st.write("---")
s_example = "r2qnrk1/1p1bbppp/p1np4/2p2p2/P1B1P3/2NP1NQ1/1PP3PP/R1B2RK1 w - - 0 12"
input = st.text_area(
"input a fen string and get a gpt 3.5 explanation of the top move",
value=s_example,
max_chars=1250,
height=50,
)
if st.button("Submit"):
with st.spinner(text="In progress"):
report_text = eval(input)
st.markdown(report_text)
else:
st.error("π Please enter API Key") |