import sys import os import streamlit as st import torch from PIL import Image st.title('Recommendation System V1') def main(): if 'turn' not in st.session_state: st.session_state['turn'] = 0 st.session_state['f_his_txt'] = [' '] st.session_state['r_t'] = 0 st.session_state['g_t_id'] = 0 def interactive(r_t, input_text): # input st.session_state['turn'] += 1 st.session_state['r_t'] = int(r_t) st.session_state['f_his_txt'].append(input_text) st.write(st.session_state) # update state # f_his_txt = st.session_state['f_his_txt'].append(input_text) g_t_id = st.session_state['g_t_id'] st.write(st.session_state) def model(input_text, g_t_id, r_t): if r_t == '': r_t = 0 # to do model g_t_id_next = g_t_id + 1 return g_t_id_next def run_model(input_text, g_t_id, r_t): g_t_id_next = model(input_text, g_t_id, r_t) # st.image(Image.open(r'EPSOLON:\data\pictures\\' + str(g_t_id_next) + '.jpg').resize((224, 224)), caption=g_t_id_next, use_column_width='auto') st.session_state['g_t_id'] = g_t_id_next st.write(st.session_state) # st.session_state['f_his_txt'] = f_his_txt # st.button('Submit', on_click=run_model, args=(f_his_txt, g_t_id, r_t)) input_text = st.text_input('Input text', value='') r_t = st.text_input('Input reward', value='0') st.button('Interactive', on_click=interactive, args=(r_t, input_text)) if __name__ == "__main__": main()