OniXinO commited on
Commit
6d7b830
·
1 Parent(s): a96c72f
Files changed (2) hide show
  1. app.py +19 -27
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,34 +1,26 @@
1
  import streamlit as st
2
- import spacy
3
 
4
- # Завантаження моделі
5
- try:
6
- nlp = spacy.load("uk_core_news_sm")
7
- except OSError:
8
- st.text("Завантаження моделі...")
9
- spacy.cli.download("uk_core_news_sm")
10
- nlp = spacy.load("uk_core_news_sm")
11
- st.text("Модель завантажена!")
12
 
13
- def process_text(text):
14
- doc = nlp(text)
15
- results = []
16
- for ent in doc.ents:
17
- results.append({"text": ent.text, "label": ent.label_})
18
- return results
19
 
20
- st.title("Розпізнавання іменованих сутностей (NER) українською мовою")
 
21
 
22
- text_input = st.text_area("Введіть текст для обробки:")
23
 
24
- if st.button("Обробка тексту"):
25
- if text_input:
26
- results = process_text(text_input)
27
- if results:
28
- st.write("Результати:")
29
- for result in results:
30
- st.write(f"- {result['text']} ({result['label']})")
 
 
31
  else:
32
- st.write("Іменовані сутності не знайдено.")
33
- else:
34
- st.write("Будь ласка, введіть текст.")
 
1
  import streamlit as st
2
+ from transformers import pipeline
3
 
4
+ @st.cache_resource
5
+ def load_model():
6
+ chatbot = pipeline("conversational", model="facebook/blenderbot-400M-distill")
7
+ return chatbot
 
 
 
 
8
 
9
+ st.title("Український Чат-бот")
 
 
 
 
 
10
 
11
+ if "history" not in st.session_state:
12
+ st.session_state.history = []
13
 
14
+ user_input = st.text_input("Ви:", "")
15
 
16
+ if st.button("Надіслати"):
17
+ chatbot = load_model()
18
+ response = chatbot(st.session_state.history + [{"role": "user", "content": user_input}])
19
+ st.session_state.history.extend([{"role": "user", "content": user_input}, {"role": "assistant", "content": response.generated_responses[0]}])
20
+
21
+ if st.session_state.history:
22
+ for message in st.session_state.history:
23
+ if message["role"] == "user":
24
+ st.write(f"Ви: {message['content']}")
25
  else:
26
+ st.write(f"Бот: {message['content']}")
 
 
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  streamlit
2
- spacy
 
 
1
  streamlit
2
+ transformers
3
+ torch