Update app.py
Browse files
app.py
CHANGED
|
@@ -3,22 +3,28 @@ import streamlit as st
|
|
| 3 |
import json
|
| 4 |
|
| 5 |
def 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 |
-
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
| 22 |
result = response.json()
|
| 23 |
st.success(f"Classification result: {result['prediction']}")
|
| 24 |
|
|
|
|
| 3 |
import json
|
| 4 |
|
| 5 |
def main():
|
|
|
|
| 6 |
st.title("FastAPI - Streamlit Integration")
|
| 7 |
|
| 8 |
+
# Получаем базовый URL из streamlit
|
| 9 |
+
base_url = st.experimental_get_query_params()['base_url'][0] if 'base_url' in st.experimental_get_query_params() else None
|
| 10 |
+
|
| 11 |
image = st.file_uploader("Choose an image", type=['jpg', 'jpeg'])
|
| 12 |
|
| 13 |
if st.button("Classify!"):
|
| 14 |
if image is not None:
|
| 15 |
st.image(image)
|
| 16 |
files = {"file": image.getvalue()}
|
| 17 |
+
# Используем базовый URL для формирования полного URL
|
| 18 |
+
url = f"{base_url}/classify"
|
| 19 |
+
res = requests.post(url, files=files)
|
| 20 |
st.write(json.loads(res.text)['prediction'])
|
| 21 |
|
| 22 |
# Эндпоинт для классификации текста
|
| 23 |
text_input = st.text_input("Enter text for classification:")
|
| 24 |
if st.button("Classify Text"):
|
| 25 |
+
# Используем базовый URL для формирования полного URL
|
| 26 |
+
url = f"{base_url}/clf_text"
|
| 27 |
+
response = requests.post(url, json={"text": text_input})
|
| 28 |
result = response.json()
|
| 29 |
st.success(f"Classification result: {result['prediction']}")
|
| 30 |
|