CoolFace
Apppublic

Solar-Iz/FastAPI

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py26 linesDownload Raw Back to root
1import requests2import streamlit as st3import json4 5def main():6 7    st.title("FastAPI - Streamlit Integration")8 9    image = st.file_uploader("Choose an image", type=['jpg', 'jpeg'])10 11    if st.button("Classify!"):12        if image is not None:13            st.image(image)14            files = {"file": image.getvalue()}15            res = requests.post("http://127.0.0.1:8000/classify", files=files)  # Замените это на актуальный URL вашего FastAPI-приложения16            st.write(json.loads(res.text)['prediction'])17 18    # Эндпоинт для классификации текста19    text_input = st.text_input("Enter text for classification:")20    if st.button("Classify Text"):21        response = requests.post("http://127.0.0.1:8000/clf_text", json={"text": text_input})  # Замените это на актуальный URL вашего FastAPI-приложения22        result = response.json()23        st.success(f"Classification result: {result['prediction']}")24 25if __name__ == '__main__':26    main()