/
himozaa
/
SE_FastAPI_Example
Обзор
Документация
Войти
/
himozaa
/
SE_FastAPI_Example
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
feature/streamlit
streamlit_app.py
89 строк
3 KB
Himozaa
feat(streamlit): add sentiment analysis interface
02 май 2026, 10:32
02 май 2026, 10:32
e9cb146
Код
Авторство
О чём код?
import streamlit as st import requests import pandas as pd API_URL = "http://127.0.0.1:8000" st.set_page_config(page_title="Анализ текста", layout="wide") st.title("Панель анализа") st.sidebar.header("⚙️ Настройки") mode = st.sidebar.selectbox("Выберете мод", ["Одиночный текст", "Batch текстов"]) if "history" not in st.session_state: st.session_state.history = [] if mode == "Одиночный текст": st.subheader("Анализ одиночного текста") text = st.text_area("Вставьте текст", height=150) col1, col2 = st.columns(2) with col1: if st.button("Проверить"): if text.strip(): response = requests.post( f"{API_URL}/predict/", json={"text": text} ) result = response.json() st.session_state.history.append({ "text": text, "label": result[0]["label"], "score": result[0]["score"] }) st.success("Анализ завершен!") st.json(result) else: st.error("Текст пуст") with col2: if st.button("Очистить историю"): st.session_state.history = [] else: st.subheader("📂 Batch анализ") texts = st.text_area( "Введите несколько текстов (по одному на строку).", height=200 ) if st.button("Проверить batch"): results = [] for t in texts.split("\n"): if t.strip(): response = requests.post( f"{API_URL}/predict/", json={"text": t} ) result = response.json()[0] results.append({ "text": t, "label": result["label"], "score": result["score"] }) st.session_state.history.append(results[-1]) if results: df = pd.DataFrame(results) st.dataframe(df) else: st.warning("Нет действительных текстов") st.subheader("🕓 История") if st.session_state.history: df = pd.DataFrame(st.session_state.history) st.dataframe(df) st.subheader("Статистика") st.bar_chart(df["label"].value_counts()) else: st.info("История пока отсутствует")