File size: 1,536 Bytes
f6414bf |
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 |
import streamlit as st
import requests
def request_prediction(model_uri, data):
payload = {'q': data}
response = requests.get(url=model_uri, params=payload)
if response.status_code != 200:
raise Exception(
"Request failed with status {}, {}".format(
response.status_code, response.text))
return response.json()
def main():
API_URI = 'http://backend:8000/prediction'
st.set_page_config("Who let's the dogs out")
st.title('Quelle est ta race de chien totem ?')
st.text('''
Pour découvrir ta race de chien, colle l'adresse d'une photo.
''')
url = st.text_input('URL de la photo')
predict_btn = st.button('Prédire')
if predict_btn:
pred = request_prediction(API_URI, url)
main_race = pred[0].split(' at')[0].lower()
main_race = '/'.join(reversed(main_race.replace('-', '').split(' ')))
if main_race.startswith('husky'):
main_race = main_race.split('/')[0]
col1, col2 = st.columns(2)
with col1:
st.image(url)
with col2:
response = requests.get(url=f'https://dog.ceo/api/breed/{main_race}/images/random').json()
if response['status'] == 'success':
st.image(response['message'])
else:
st.text(main_race)
st.text(response)
st.write('Les races qui te correspondent le plus sont :')
for race in pred:
st.write(race)
if __name__ == '__main__':
main()
|