Spaces:
Sleeping
Sleeping
Commit
·
4760da5
1
Parent(s):
3db33cc
prevent reloading logo and info
Browse files
app.py
CHANGED
|
@@ -1,6 +1,4 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import torch
|
| 3 |
-
import torch.nn as nn
|
| 4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 5 |
import requests
|
| 6 |
from PIL import Image
|
|
@@ -16,17 +14,15 @@ Answer: [/INST]
|
|
| 16 |
"""
|
| 17 |
|
| 18 |
# Load the model and tokenizer
|
| 19 |
-
@st.
|
| 20 |
def load_model():
|
| 21 |
model_name = "walledai/walledguard-c"
|
| 22 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 23 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 24 |
return tokenizer, model
|
| 25 |
|
| 26 |
-
tokenizer, model = load_model()
|
| 27 |
-
|
| 28 |
# Function to load image from URL
|
| 29 |
-
@st.
|
| 30 |
def load_image_from_url(url):
|
| 31 |
response = requests.get(url)
|
| 32 |
img = Image.open(BytesIO(response.content))
|
|
@@ -40,6 +36,9 @@ user_input = st.text_area("Enter the text you want to evaluate:", height=100)
|
|
| 40 |
|
| 41 |
if st.button("Evaluate"):
|
| 42 |
if user_input:
|
|
|
|
|
|
|
|
|
|
| 43 |
# Prepare input
|
| 44 |
input_ids = tokenizer.encode(TEMPLATE.format(prompt=user_input), return_tensors="pt")
|
| 45 |
|
|
@@ -61,7 +60,6 @@ if st.button("Evaluate"):
|
|
| 61 |
st.warning("Please enter some text to evaluate.")
|
| 62 |
|
| 63 |
# Add logo at the bottom center
|
| 64 |
-
#st.markdown("---")
|
| 65 |
col1, col2, col3 = st.columns([1,2,1])
|
| 66 |
with col2:
|
| 67 |
logo_url = "https://github.com/walledai/walledeval/assets/32847115/d8b1d14f-7071-448b-8997-2eeba4c2c8f6"
|
|
@@ -69,7 +67,6 @@ with col2:
|
|
| 69 |
st.image(logo, use_column_width=True, width=500) # Adjust the width as needed
|
| 70 |
|
| 71 |
# Add information about Walled Guard Advanced
|
| 72 |
-
#st.markdown("---")
|
| 73 |
col1, col2, col3 = st.columns([1,2,1])
|
| 74 |
with col2:
|
| 75 |
-
st.info("For a more performant version, check out Walled Guard Advanced. Connect with us at admin@walled.ai for more information.")
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
import requests
|
| 4 |
from PIL import Image
|
|
|
|
| 14 |
"""
|
| 15 |
|
| 16 |
# Load the model and tokenizer
|
| 17 |
+
@st.cache(allow_output_mutation=True)
|
| 18 |
def load_model():
|
| 19 |
model_name = "walledai/walledguard-c"
|
| 20 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 21 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 22 |
return tokenizer, model
|
| 23 |
|
|
|
|
|
|
|
| 24 |
# Function to load image from URL
|
| 25 |
+
@st.cache(hash_funcs={Image.Image: lambda img: None})
|
| 26 |
def load_image_from_url(url):
|
| 27 |
response = requests.get(url)
|
| 28 |
img = Image.open(BytesIO(response.content))
|
|
|
|
| 36 |
|
| 37 |
if st.button("Evaluate"):
|
| 38 |
if user_input:
|
| 39 |
+
# Load model and tokenizer
|
| 40 |
+
tokenizer, model = load_model()
|
| 41 |
+
|
| 42 |
# Prepare input
|
| 43 |
input_ids = tokenizer.encode(TEMPLATE.format(prompt=user_input), return_tensors="pt")
|
| 44 |
|
|
|
|
| 60 |
st.warning("Please enter some text to evaluate.")
|
| 61 |
|
| 62 |
# Add logo at the bottom center
|
|
|
|
| 63 |
col1, col2, col3 = st.columns([1,2,1])
|
| 64 |
with col2:
|
| 65 |
logo_url = "https://github.com/walledai/walledeval/assets/32847115/d8b1d14f-7071-448b-8997-2eeba4c2c8f6"
|
|
|
|
| 67 |
st.image(logo, use_column_width=True, width=500) # Adjust the width as needed
|
| 68 |
|
| 69 |
# Add information about Walled Guard Advanced
|
|
|
|
| 70 |
col1, col2, col3 = st.columns([1,2,1])
|
| 71 |
with col2:
|
| 72 |
+
st.info("For a more performant version, check out Walled Guard Advanced. Connect with us at admin@walled.ai for more information.")
|