forked from Michel-Maia/Tech_Challenge_grupo12
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
37 lines (29 loc) · 978 Bytes
/
app.py
File metadata and controls
37 lines (29 loc) · 978 Bytes
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
import streamlit as st
import requests
import json
API_URL = 'http://localhost:8000'
st.title('Interface de teste da API Embrapa')
endpoints = {
'/dados': 'Obter todos os dados',
'/dados/{arquivo}': 'Obter dados de um arquivo específico',
'/listar_arquivos': 'Listar arquivos disponíveis'
}
selected_endpoint = st.selectbox('Selecione um endpoint:', list(endpoints.keys()))
st.write(endpoints[selected_endpoint])
if selected_endpoint == '/dados/{arquivo}':
arquivo = st.text_input('Nome do arquivo:')
else:
arquivo = None
if st.button('Fazer Requisição'):
url = f'{API_URL}{selected_endpoint}'
if arquivo:
url = url.format(arquivo=arquivo)
response = requests.get(url)
if response.status_code == 200:
try:
data = response.json()
st.json(data)
except json.JSONDecodeError:
st.text(response.text)
else:
st.error(f'Erro na requisição: {response.status_code}')