File size: 1,006 Bytes
dbfc835
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import requests
import json

def main():

    st.title("FastAPI - Streamlit Integration")

    # Эндпоинт для классификации текста
    text_input = st.text_input("Enter text for classification:")
    if st.button("Classify Text"):
        response = requests.post("http://127.0.0.1:8000/clf_text", json={"text": text_input})
        result = response.json()
        st.success(f"Classification result: {result['prediction']}")

    # Эндпоинт для классификации изображений
    image_path = st.file_uploader("Upload an image for classification:", type=["jpg", "png"])
    if image_path is not None:
        if st.button("Classify Image"):
            files = {"file": image_path.read()}
            response = requests.post("http://127.0.0.1:8000/classify", files=files)
            result = response.json()
            st.success(f"Classification result: {result['prediction']}")

if __name__ == '__main__':
    main()