BuildPlay / home_view /ui_home.py
Kim Adams
trying something else for checkboxes
741ce5e
raw
history blame
4.08 kB
import gradio as gr
import pandas as pd
from home_view.app_theme import SoftBlue
from utilities import constants
from sketch import sketch as sk
from slack_processing.slack_data_prep import FetchSlack, ProcessSlack, CreateEmbeddings
from create_games.create_games_slack import LoadThemes,GetPlayersAndIndex,CreateGameForGroup,GetPeopleByThemesDF
startDF=pd.DataFrame()
slackDF=pd.DataFrame()
embeddingsDF=pd.DataFrame()
playersDF=pd.DataFrame()
gamesDF=pd.DataFrame()
playersValues=[]
selected= []
players=[]
def FetchData():
startDF=FetchSlack()
slackDF=ProcessSlack()
embeddingsDF=CreateEmbeddings()
gamesDF=LoadThemes()
playersDF=GetPeopleByThemesDF()
return startDF, slackDF, embeddingsDF, playersDF, gamesDF
def Init():
global startDF, slackDF, embeddingsDF, gamesDF,playersDF,playersValues
startDF=FetchSlack()
slackDF=ProcessSlack()
embeddingsDF=CreateEmbeddings()
gamesDF=LoadThemes()
playersValues=GetPlayersAndIndex()
playersDF = GetPeopleByThemesDF()
playersCB.choices = playersValues
def SetSelected(playersCB):
global playersValues,selected,players
selected=[]
players=[]
for check in playersCB:
selected.append(check)
for player_name, player_id in playersValues:
if player_id == check:
if player_name not in players:
players.append(player_name)
print("player_name", player_name)
break
def PlayGame():
return gr.update(visible=True)
def Predict(sketch):
confidences = sk.Predict(sketch)
print("Predict():", confidences)
return confidences
def CreateGame():
global players, gameTitle
print("CreateGame():", players)
print("playersCB.choices:", playersCB.choices)
game_ideas = CreateGameForGroup(players)
#print("CreateGame():", game_ideas)
if not game_ideas is None:
game_ideas_dict = game_ideas.to_dict('records')
return game_ideas, game_ideas_dict[0]['Description'],game_ideas_dict[0]['Name']
return None, constants.NO_GAME_TITLE, constants.NO_GAME
df1 =gr.Dataframe(type="pandas", value=startDF)
df2 =gr.Dataframe(type="pandas", value=slackDF)
df3 =gr.Dataframe(type="pandas", value=embeddingsDF)
df4 =gr.Dataframe(type="pandas", value= playersDF)
df5 =gr.Dataframe(type="pandas", value=gamesDF)
with gr.Blocks() as ui:
with gr.Row():
logo=gr.Image(value=constants.BUILDPLAY_LOGO, width=200, height=200, show_download_button=False, container=False)
directions= gr.Markdown(constants.DIRECTIONS, container=False)
with gr.Column():
playersCB = gr.CheckboxGroup ([], type="value", label=constants.PLAYERS, info=constants.PLAYERS_INFO )
createBtn = gr.Button(value=constants.CREATE_GAME, variant="primary")
gameTitle=gr.Markdown(constants.GAME_TITLE, container=False)
desc=gr.TextArea(info=constants.GAME_DESC, interactive=False, show_label=False,
placeholder=constants.GAME_DESC_PLACEHOLDER, lines=3)
playBtn = gr.Button(value=constants.PLAY_GAME, variant="primary")
with gr.Row(visible=False) as holder:
sketch=gr.Image(image_mode="L", source="canvas", width=600, height =600, invert_colors=True, interactive=True,
brush_radius=.5, type="numpy", label="Sketch", show_label=True, show_download_button=False)
label=gr.Label()
sketch.change(Predict, inputs=[sketch], outputs=[label])
with gr.Blocks() as dfs:
fetchBtn=gr.Button(value=constants.FETCH_DATA, variant="primary")
gr.TabbedInterface([df1,df2,df3,df4,df5], (constants.UI1, constants.UI2, constants.UI3, constants.UI4, constants.UI5), theme=SoftBlue())
fetchBtn.click(FetchData, inputs=[], outputs=[df1,df2,df3,df4,df5])
playersCB.change(SetSelected, inputs=[playersCB], outputs=[])
createBtn.click(CreateGame, inputs=[], outputs=[df4,desc,gameTitle])
playBtn.click(PlayGame, inputs=[], outputs=[holder])
combo=gr.TabbedInterface([ui,dfs], ("BuildPlay", "DataFrames"),theme=SoftBlue())
Init()