FastAPI / app.py
Solar-Iz's picture
Update app.py
e294354
raw
history blame
1.22 kB
import requests
import streamlit as st
import json
def main():
st.title("FastAPI - Streamlit Integration")
# Получаем базовый URL из streamlit
base_url = st.experimental_get_query_params().get('base_url', [None])[0]
image = st.file_uploader("Choose an image", type=['jpg', 'jpeg'])
if st.button("Classify!"):
if image is not None:
st.image(image)
files = {"file": image.getvalue()}
# Используем базовый URL для формирования полного URL
url = f"{base_url}/classify"
res = requests.post(url, files=files)
st.write(json.loads(res.text)['prediction'])
# Эндпоинт для классификации текста
text_input = st.text_input("Enter text for classification:")
if st.button("Classify Text"):
# Используем базовый URL для формирования полного URL
url = f"{base_url}/clf_text"
response = requests.post(url, json={"text": text_input})
result = response.json()
st.success(f"Classification result: {result['prediction']}")
if __name__ == '__main__':
main()