File size: 1,060 Bytes
acc4523
632b74a
acc4523
 
 
 
2ddd2b4
c9d4442
632b74a
 
 
 
 
 
2ddd2b4
632b74a
 
acc4523
 
 
2ddd2b4
acc4523
 
 
 
 
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 requests
import streamlit as st
import json

def main():

    st.title("FastAPI - Streamlit Integration")

    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()}
            res = requests.post("http://127.0.0.1:8000/classify", files=files)  # Замените это на актуальный URL вашего FastAPI-приложения
            st.write(json.loads(res.text)['prediction'])

    # Эндпоинт для классификации текста
    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})  # Замените это на актуальный URL вашего FastAPI-приложения
        result = response.json()
        st.success(f"Classification result: {result['prediction']}")

if __name__ == '__main__':
    main()