nakas's picture
Update Main.py
d4df15f
raw
history blame
2.06 kB
import streamlit as st
from model import GeneralModel
import os
import chess
import chess.engine
import stat
def app():
# Creating an object of prediction service
pred = GeneralModel()
api_key = st.sidebar.text_input("APIkey (current project not working)", 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()
#parse info eventually but lets just do it all as a test
evalstring = str(info)
stringprompt = 'Based on the chess board position at this fen string ' + fenstring + 'can you give an in depth analysis as to why c3d5 is the best move to play '
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 to GPT-3 strong move explination coach (currently not working)")
# st.write("---")
s_example = "I will input chess fen strings and you reply back with the top three moves I should do next and why I should do each move. you also should evaluate my opponents play r2qnrk1/1p1bbppp/p1np4/2p2p2/P1B1P3/2NP1NQ1/1PP3PP/R1B2RK1 w - - 0 12"
input = st.text_area(
"Use the example below or write your own text",
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")