dfourneaux/stackoverflow
0
1import streamlit as st2import requests3 4API_URL = "http://127.0.0.1:8000"5 6st.set_page_config(page_title="StackOverflow Tag Predictor", page_icon="🤖")7 8st.title("🤖 StackOverflow Tag Predictor")9 10st.markdown("Prédis les tags d’un titre StackOverflow avec ton modèle ML.")11 12# ---------- Partie 1 : Titre unique ----------13st.header("🔹 Prédiction simple")14 15title = st.text_input("Entre ton titre StackOverflow :")16 17if st.button("Prédire les tags"):18 if title.strip() == "":19 st.warning("⛔ Entre un titre valide.")20 else:21 payload = {"title": title}22 response = requests.post(f"{API_URL}/predict-tags", json=payload)23 24 if response.status_code == 200:25 data = response.json()26 st.success("✅ Tags prédits :")27 st.write(data["predicted_tags"])28 else:29 st.error(f"❌ Erreur API : {response.status_code}")30 st.write(response.text)31 32# ---------- Partie 2 : Batch ----------33st.header("🔹 Prédiction batch")34 35batch_text = st.text_area("Colle plusieurs titres (1 par ligne) :")36 37if st.button("Prédire les tags en batch"):38 titles = [line.strip() for line in batch_text.split("\n") if line.strip() != ""]39 40 if len(titles) == 0:41 st.warning("⛔ Aucun titre valide fourni.")42 else:43 payload = {"titles": titles}44 45 response = requests.post(f"{API_URL}/predict-tags-batch", json=payload)46 47 if response.status_code == 200:48 data = response.json()49 50 st.success("✅ Résultats :")51 52 for res in data["results"]:53 st.markdown(f"### ➤ {res['title']}")54 st.write("Tags prédits :", res["predicted_tags"])55 56 else:57 st.error(f"❌ Erreur API : {response.status_code}")58 st.write(response.text)59 