Spaces:
Sleeping
Sleeping
| import altair as alt | |
| import numpy as np | |
| import pandas as pd | |
| import streamlit as st | |
| import os | |
| os.environ["TRANSFORMERS_CACHE"] = "/app/cache" | |
| os.environ["HF_HOME"] = "/app/cache" | |
| from huggingface_hub import login | |
| hf_token = os.getenv("hf_token") | |
| login(token=hf_token) | |
| from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline | |
| def load_classifier(): | |
| model_name = "mahsharyahan/EMBEDDIA_crosloengual_bert_Sl" | |
| model = AutoModelForSequenceClassification.from_pretrained(model_name, token=hf_token) | |
| tokenizer = AutoTokenizer.from_pretrained(model_name, token=hf_token) | |
| return pipeline("text-classification", model=model, tokenizer=tokenizer) | |
| # Define sample texts | |
| sample_texts = [ | |
| "Slovenija je čudovita država z bogato kulturo.", | |
| "Vreme danes ni najboljše, pričakuje se dež.", | |
| "Ta film mi je bil zelo všeč.", | |
| "Ne maram zamud pri javnem prevozu.", | |
| "To je bil odličen športni dogodek." | |
| ] | |
| st.title("AI Text Detection(Prototype)") | |
| # Sample selector | |
| selected_sample = st.selectbox( | |
| "Or select a sample text to detect:", | |
| ["(Choose a sample)"] + sample_texts | |
| ) | |
| # Text area for custom input, pre-filled if a sample is chosen | |
| if selected_sample != "(Choose a sample)": | |
| user_input = st.text_area("Enter text to dectet:", value=selected_sample) | |
| else: | |
| user_input = st.text_area("Enter text to dected AI:") | |
| if st.button("Detect"): | |
| if user_input.strip(): | |
| classifier = load_classifier() | |
| result = classifier(user_input) | |
| label = result[0]['label'] | |
| score = result[0]['score'] | |
| st.write(f"**Label:** {label}") | |
| st.write(f"**Confidence:** {score:.2f}") | |
| else: | |
| st.warning("Please enter some text.") | |