File size: 1,222 Bytes
acc4523
632b74a
acc4523
 
 
 
 
c9d4442
e294354
c9d4442
632b74a
 
 
 
 
 
c9d4442
 
 
632b74a
 
acc4523
 
 
c9d4442
 
 
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
27
28
29
30
31
32
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()