Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,27 @@
|
|
| 1 |
-
import nltk
|
| 2 |
-
from nltk.tokenize import word_tokenize
|
| 3 |
import streamlit as st
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
def detect_bad_words(text, bad_words):
|
| 12 |
-
# Metni küçük harflere dönüştür ve tokenize et
|
| 13 |
-
words = word_tokenize(text.lower())
|
| 14 |
-
|
| 15 |
-
# Kötü kelimeleri tespit et
|
| 16 |
-
detected_bad_words = [word for word in words if word in bad_words]
|
| 17 |
-
|
| 18 |
-
return detected_bad_words
|
| 19 |
|
| 20 |
-
|
| 21 |
-
user_text = st.text_area("Lütfen metni girin: ")
|
| 22 |
-
detected_words = detect_bad_words(user_text, bad_words)
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
# Load the model and tokenizer
|
| 6 |
+
@st.cache_resource
|
| 7 |
+
def load_model():
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained("01-ai/Yi-6B-Chat")
|
| 9 |
+
model = AutoModelForCausalLM.from_pretrained("01-ai/Yi-6B-Chat")
|
| 10 |
+
return tokenizer, model
|
| 11 |
|
| 12 |
+
tokenizer, model = load_model()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
st.title("Chat with AI")
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
# User input
|
| 17 |
+
user_input = st.text_input("You: ", "Hello, how are you?")
|
| 18 |
+
|
| 19 |
+
if user_input:
|
| 20 |
+
# Tokenize input and generate response
|
| 21 |
+
inputs = tokenizer(user_input, return_tensors="pt")
|
| 22 |
+
with torch.no_grad():
|
| 23 |
+
outputs = model.generate(inputs.input_ids, max_length=50, num_return_sequences=1)
|
| 24 |
+
|
| 25 |
+
# Decode and display the response
|
| 26 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 27 |
+
st.write(f"AI: {response}")
|