Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +18 -9
src/streamlit_app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import torch
|
| 3 |
-
from transformers import pipeline
|
| 4 |
import time
|
| 5 |
|
| 6 |
st.set_page_config(
|
|
@@ -21,18 +21,27 @@ st.markdown("""
|
|
| 21 |
|
| 22 |
@st.cache_resource
|
| 23 |
def load_pipelines():
|
|
|
|
| 24 |
with st.spinner('π Loading AI models (2-3 min)...'):
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
generator = pipeline("text-generation", model="Kunal7370944861/Email-Writer-AI")
|
| 27 |
translator = pipeline("translation", model="DDDSSS/translation_en-zh")
|
|
|
|
| 28 |
return classifier, generator, translator
|
| 29 |
|
| 30 |
# Load models safely
|
| 31 |
try:
|
| 32 |
classifier, generator, translator = load_pipelines()
|
| 33 |
-
st.success("β
All 3 pipelines ready!")
|
| 34 |
except Exception as e:
|
| 35 |
-
st.error(f"Model loading error: {str(e)}")
|
| 36 |
st.stop()
|
| 37 |
|
| 38 |
def classify_email(text, classifier):
|
|
@@ -65,10 +74,10 @@ def translate_reply(text, translator):
|
|
| 65 |
st.markdown('<h1 class="main-header">π€ Email Reply Assistant</h1>', unsafe_allow_html=True)
|
| 66 |
st.markdown("**AI-powered: Classify β Generate Reply β Translate to Chinese**")
|
| 67 |
|
| 68 |
-
# Sidebar
|
| 69 |
with st.sidebar:
|
| 70 |
st.header("π§ Pipeline Status")
|
| 71 |
-
st.success("β
**Pipeline 1**: `
|
| 72 |
st.success("β
**Pipeline 2**: `Kunal7370944861/Email-Writer-AI`")
|
| 73 |
st.success("β
**Pipeline 3**: `DDDSSS/translation_en-zh`")
|
| 74 |
st.markdown("---")
|
|
@@ -98,10 +107,10 @@ with col2:
|
|
| 98 |
if 'processed' in st.session_state and st.session_state.processed:
|
| 99 |
email_text = st.session_state.email
|
| 100 |
|
| 101 |
-
# Pipeline 1:
|
| 102 |
with st.container():
|
| 103 |
st.markdown('<div class="pipeline-card">', unsafe_allow_html=True)
|
| 104 |
-
st.markdown("### π’ **Pipeline 1: Email
|
| 105 |
label, score = classify_email(email_text, classifier)
|
| 106 |
|
| 107 |
col_a, col_b = st.columns(2)
|
|
@@ -150,4 +159,4 @@ with col2:
|
|
| 150 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 151 |
|
| 152 |
st.markdown("---")
|
| 153 |
-
st.markdown("*Powered by Streamlit + Transformers |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import torch
|
| 3 |
+
from transformers import pipeline, AutoTokenizer
|
| 4 |
import time
|
| 5 |
|
| 6 |
st.set_page_config(
|
|
|
|
| 21 |
|
| 22 |
@st.cache_resource
|
| 23 |
def load_pipelines():
|
| 24 |
+
"""Load all 3 pipelines with custom classifier"""
|
| 25 |
with st.spinner('π Loading AI models (2-3 min)...'):
|
| 26 |
+
# β
YOUR CUSTOM CLASSIFIER (replaced)
|
| 27 |
+
tok = AutoTokenizer.from_pretrained("distilbert-base-uncased")
|
| 28 |
+
classifier = pipeline(
|
| 29 |
+
"text-classification",
|
| 30 |
+
model="byinab/custom-email-classifier",
|
| 31 |
+
tokenizer=tok,
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
generator = pipeline("text-generation", model="Kunal7370944861/Email-Writer-AI")
|
| 35 |
translator = pipeline("translation", model="DDDSSS/translation_en-zh")
|
| 36 |
+
|
| 37 |
return classifier, generator, translator
|
| 38 |
|
| 39 |
# Load models safely
|
| 40 |
try:
|
| 41 |
classifier, generator, translator = load_pipelines()
|
| 42 |
+
st.success("β
All 3 pipelines ready! (Custom Email Classifier Loaded)")
|
| 43 |
except Exception as e:
|
| 44 |
+
st.error(f"β Model loading error: {str(e)}")
|
| 45 |
st.stop()
|
| 46 |
|
| 47 |
def classify_email(text, classifier):
|
|
|
|
| 74 |
st.markdown('<h1 class="main-header">π€ Email Reply Assistant</h1>', unsafe_allow_html=True)
|
| 75 |
st.markdown("**AI-powered: Classify β Generate Reply β Translate to Chinese**")
|
| 76 |
|
| 77 |
+
# Sidebar - UPDATED with your custom classifier
|
| 78 |
with st.sidebar:
|
| 79 |
st.header("π§ Pipeline Status")
|
| 80 |
+
st.success("β
**Pipeline 1**: `byinab/custom-email-classifier`")
|
| 81 |
st.success("β
**Pipeline 2**: `Kunal7370944861/Email-Writer-AI`")
|
| 82 |
st.success("β
**Pipeline 3**: `DDDSSS/translation_en-zh`")
|
| 83 |
st.markdown("---")
|
|
|
|
| 107 |
if 'processed' in st.session_state and st.session_state.processed:
|
| 108 |
email_text = st.session_state.email
|
| 109 |
|
| 110 |
+
# Pipeline 1: YOUR CUSTOM CLASSIFIER
|
| 111 |
with st.container():
|
| 112 |
st.markdown('<div class="pipeline-card">', unsafe_allow_html=True)
|
| 113 |
+
st.markdown("### π’ **Pipeline 1: Custom Email Classifier**")
|
| 114 |
label, score = classify_email(email_text, classifier)
|
| 115 |
|
| 116 |
col_a, col_b = st.columns(2)
|
|
|
|
| 159 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 160 |
|
| 161 |
st.markdown("---")
|
| 162 |
+
st.markdown("*Powered by Streamlit + Transformers | Custom Email Classifier*")
|