Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,48 +1,49 @@
|
|
1 |
-
#!/usr/bin/env python
|
2 |
-
# coding: utf-8
|
3 |
-
|
4 |
import streamlit as st
|
5 |
from tensorflow.keras.models import load_model
|
|
|
6 |
from transformers import logging
|
7 |
|
8 |
# Hugging Face Transformers kütüphanesinden gelen hataları kapat
|
9 |
logging.set_verbosity_error()
|
10 |
|
11 |
-
|
12 |
st.title('Chat with Me')
|
|
|
|
|
13 |
model = load_model('text_classification_model.h5')
|
14 |
|
15 |
# Chat history
|
16 |
-
if '
|
17 |
-
st.session_state.
|
18 |
|
19 |
-
#
|
20 |
soru = st.text_input('Sor:')
|
21 |
|
22 |
-
#
|
23 |
-
def
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
#
|
27 |
if st.button('Sor'):
|
28 |
if soru:
|
29 |
-
response =
|
30 |
-
st.session_state.
|
31 |
-
st.session_state.
|
32 |
-
st.session_state.last_question = soru
|
33 |
-
st.session_state.last_response = extract_text(response.parts)
|
34 |
st.experimental_rerun()
|
35 |
|
36 |
-
#
|
37 |
-
for message in reversed(st.session_state.
|
38 |
-
if message
|
39 |
st.markdown(f'<div style="text-align: right; background-color: #2F2F2F; padding: 10px; border-radius: 10px; margin: 10px; width: fit-content;">👤 Sen: {message["text"]}</div>', unsafe_allow_html=True)
|
40 |
-
elif message
|
41 |
st.markdown(f'<div style="text-align: left; background-color: #2E2E2E; padding: 10px; border-radius: 10px; margin: 10px; width: fit-content;">🤖 Bot: {message["text"]}</div>', unsafe_allow_html=True)
|
42 |
|
43 |
-
#
|
44 |
if st.button('Yeni Sohbet'):
|
45 |
-
st.session_state.
|
46 |
-
st.
|
47 |
-
st.session_state.last_response = ''
|
48 |
-
st.experimental_rerun()
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from tensorflow.keras.models import load_model
|
3 |
+
import numpy as np
|
4 |
from transformers import logging
|
5 |
|
6 |
# Hugging Face Transformers kütüphanesinden gelen hataları kapat
|
7 |
logging.set_verbosity_error()
|
8 |
|
9 |
+
# Streamlit başlık
|
10 |
st.title('Chat with Me')
|
11 |
+
|
12 |
+
# Model yükleme (burada dil modeli veya sohbet modeli olmalı)
|
13 |
model = load_model('text_classification_model.h5')
|
14 |
|
15 |
# Chat history
|
16 |
+
if 'chat_history' not in st.session_state:
|
17 |
+
st.session_state.chat_history = []
|
18 |
|
19 |
+
# Kullanıcıdan giriş alma
|
20 |
soru = st.text_input('Sor:')
|
21 |
|
22 |
+
# Yanıt üretme fonksiyonu (modelinize göre bu kısım değişebilir)
|
23 |
+
def generate_response(input_text):
|
24 |
+
# Örneğin, modelinize uygun şekilde giriş ve çıkışları dönüştürün
|
25 |
+
# Bu basit bir örnek, modelinizin gereksinimlerine göre düzenlemelisiniz
|
26 |
+
input_vector = np.array([input_text]) # Modelin beklediği giriş formatı
|
27 |
+
prediction = model.predict(input_vector)
|
28 |
+
response = "Bu bir örnek yanıttır." # Modelden gelen yanıtı buraya yazın
|
29 |
+
return response
|
30 |
|
31 |
+
# "Sor" butonuna tıklama olayını işleme
|
32 |
if st.button('Sor'):
|
33 |
if soru:
|
34 |
+
response = generate_response(soru)
|
35 |
+
st.session_state.chat_history.append({'role': 'user', 'text': soru})
|
36 |
+
st.session_state.chat_history.append({'role': 'model', 'text': response})
|
|
|
|
|
37 |
st.experimental_rerun()
|
38 |
|
39 |
+
# Sohbet geçmişini gösterme
|
40 |
+
for message in reversed(st.session_state.chat_history):
|
41 |
+
if message['role'] == 'user':
|
42 |
st.markdown(f'<div style="text-align: right; background-color: #2F2F2F; padding: 10px; border-radius: 10px; margin: 10px; width: fit-content;">👤 Sen: {message["text"]}</div>', unsafe_allow_html=True)
|
43 |
+
elif message['role'] == 'model':
|
44 |
st.markdown(f'<div style="text-align: left; background-color: #2E2E2E; padding: 10px; border-radius: 10px; margin: 10px; width: fit-content;">🤖 Bot: {message["text"]}</div>', unsafe_allow_html=True)
|
45 |
|
46 |
+
# "Yeni Sohbet" butonuna tıklama olayını işleme
|
47 |
if st.button('Yeni Sohbet'):
|
48 |
+
st.session_state.chat_history = []
|
49 |
+
st.experimental_rerun()
|
|
|
|