File size: 1,637 Bytes
3c6e15d 2353bb5 3c6e15d 2353bb5 3c6e15d d3372d9 2353bb5 |
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 |
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()
|