Hello people of the community! I am new to streamlit and want to develop a web app that is similar to Tinder application. First of all, the user will have to select the gender and then click on the ‘Find’ button and an image will be displayed. As soon as you clicked on button, two new buttons will be displayed i.e. ‘Like’ and ‘Dislike’. Now, the purpose of the ‘Like’ button is to show the similar image i.e. if a man is having black hair, then till the user is pressing the like button, he will be displayed man with black hair. If the user press dislike button, he will be displayed random image either gender with black, blonde or bald hair.
My corresponding code is here:
from tkinter import CENTER import streamlit as st import numpy as np import pandas as pd import os import matplotlib.pyplot as plt import random import cv2 from PIL import Image file_path = os.listdir("D:/2.Masters/Sem_4/EV/Projects/Tinder_Project/Data/") def user_input(): st.title("Tinder Application") st.write("""### This is the other basic model of the Tinder Application""") gender = st.selectbox('Pick your gender', ['Male', 'Female']) men =  women =  for images in file_path: if 'female' in images: women.append(images) elif 'male' in images: men.append(images) if gender == 'Male': name = random.choice(men) elif gender == 'Female': name = random.choice(women) return name, gender def find(name): image = cv2.imread('D:/2.Masters/Sem_4/EV/Projects/Tinder_Project/Data/' + name) image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) return image def like(gender, name): men_black_hair =  women_black_hair =  men_no_hair =  women_blonde_hair =  men_blonde_hair =  for images in file_path: if 'female_black_hair' in images: women_black_hair.append(images) elif 'male_black_hair' in images: men_black_hair.append(images) elif 'female_blonde_hair' in images: women_blonde_hair.append(images) elif 'male_no_hair' in images: men_no_hair.append(images) elif 'male_blonde_hair' in images: men_blonde_hair.append(images) if gender == 'Male' and 'black' in name: name = random.choice(men_black_hair) elif gender == 'Male' and 'blonde' in name: name = random.choice(men_no_hair) elif gender == 'Male' and 'no' in name: name = random.choice(men_blonde_hair) elif gender == 'Female' and 'black' in name: name = random.choice(women_black_hair) elif gender == 'Female' and 'blonde' in name: name = random.choice(women_blonde_hair) like_image = cv2.imread('D:/2.Masters/Sem_4/EV/Projects/Tinder_Project/Data/' + name) like_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) return image def dislike(name): image = find(name) return image def display(image): if st.button('Find'): col1, col2, col3 = st.columns([1,1,1]) with col1: like = st.button('Like') with col3: dislike = st.button('Dislike') if like: image = like(image) elif dislike: image = dislike(image) st.image(image) name, gender = user_input() image = find(name) display(image)
The problem is that the images are not displayed after clicking on Like or Dislike button. In fact, everything reruns from top to bottom.
I know the solution is to use state_session and callbacks, but I don’t know how to implement that. Any help would be appreciable!