CoolFace
Apppublic

HarshulNanda/VV

sourceHugging Faceupdated 3y agoView on Hugging Face
1likes
app.py90 linesDownload Raw Back to root
1import base642import os3import time4import streamlit as st5from PIL import Image6from transformers import pipeline7 8def zero_shot_classification(text, progress):9    classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")10    labels = ["Criminal Activity", "Safe and Ethical"]11    12    for i in range(0, 101, 10):13        progress.progress(i)14        time.sleep(0.1)15 16    result = classifier(text, labels)17    return result["labels"][0]18 19st.set_page_config(20    page_title="Verbal Vanguard",21    # page_icon=Image.open("./assets/my_photo.png")22)23 24def custom_css(css: str):25    st.markdown(f'<style>{css}</style>', unsafe_allow_html=True)26 27css = f"""28body, h1, h2, h3, h4, h5, h6, p, div, a, span, label, input, button, textarea {{29    color: white !important;30}}31 32::placeholder {{33    color: white !important;34    opacity: 1 !important;35}}36 37div.stNavBar {{38    background-color: #222 !important;39}}40 41div.stButton {{42    background-color: #1B0099 !important;43    color: #fff !important;44    border-color: #fff !important;45}}46 47div.stButton button:hover {{48    background-color: #1573F8 !important;49    color: #fff !important;50    border-color: #fff !important;51}}52 53div.stButton > button:first-child {{ border: 1px solid #FFF; border-radius:20px 20px 20px 20px; background: none;}}54 55div.stButton > button:first-child:hover {{56    background: #1B0099;57    color: white;58}}59 60h1, h3, span {{61    color: #fff;62}}63 64footer, header {{65    visibility: hidden;66}}67"""68 69custom_css(css)70 71# with st.sidebar:72#     st.markdown("<center><h1><b>Verbal Vanguard</b></h1><h3>Crime & Safety Identifier</h3></center>", unsafe_allow_html=True)73 74def main():75    st.title("Verbal Vanguard")76    st.markdown("<h3>Crime & Safety Identifier</h3><br /><span>This prototype utilizes a BERT model to evaluate conversations and categorize them as either 'Criminal Activity' or 'Safe and Ethical'. The model is under training phase.</span><br />", unsafe_allow_html=True)77 78    user_text = st.text_area("Enter a conversation:- ", height=300)79 80    if st.button("Classify"):81        if not user_text.strip():82            st.warning("Please input a conversation to classify.")83        else:84            progress = st.progress(0)85            prediction = zero_shot_classification(user_text, progress)86            progress.empty()87            st.success(f"Predicted Category: {prediction}")88 89if __name__ == "__main__":90    main()