pax-dare-lab commited on
Commit
c6d01f1
1 Parent(s): b7012f5

Add HugChat

Browse files
Files changed (3) hide show
  1. app.py +0 -24
  2. app_old.py +24 -0
  3. requirements.txt +2 -1
app.py CHANGED
@@ -1,24 +0,0 @@
1
- from transformers import AutoModelForQuestionAnswering, BertJapaneseTokenizer
2
- import streamlit as st
3
- import torch
4
-
5
- model_name = 'KoichiYasuoka/bert-base-japanese-wikipedia-ud-head'
6
-
7
- model = AutoModelForQuestionAnswering.from_pretrained(model_name)
8
- tokenizer = BertJapaneseTokenizer.from_pretrained(model_name)
9
-
10
- context = "私の名前は山田です。趣味は動画鑑賞とショッピングです。年齢は30歳です。出身は大阪府です。仕事は医者です。"
11
-
12
- st.title("AI assistant")
13
- user_input = st.text_input("You:", "")
14
- if st.button("Send"):
15
- inputs = tokenizer.encode_plus(user_input, context, add_special_tokens=True, return_tensors="pt")
16
- input_ids = inputs["input_ids"].tolist()[0]
17
- output = model(**inputs)
18
-
19
- answer_start = torch.argmax(output.start_logits)
20
- answer_end = torch.argmax(output.end_logits) + 1
21
- answer = tokenizer.convert_tokens_to_string(tokenizer.convert_ids_to_tokens(input_ids[answer_start:answer_end]))
22
- answer = answer.replace(' ', '')
23
-
24
- st.text_area("Chatbot:", answer, height=100)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app_old.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForQuestionAnswering, BertJapaneseTokenizer
2
+ import streamlit as st
3
+ import torch
4
+
5
+ model_name = 'KoichiYasuoka/bert-base-japanese-wikipedia-ud-head'
6
+
7
+ model = AutoModelForQuestionAnswering.from_pretrained(model_name)
8
+ tokenizer = BertJapaneseTokenizer.from_pretrained(model_name)
9
+
10
+ context = "私の名前は山田です。趣味は動画鑑賞とショッピングです。年齢は30歳です。出身は大阪府です。仕事は医者です。"
11
+
12
+ st.title("AI assistant")
13
+ user_input = st.text_input("You:", "")
14
+ if st.button("Send"):
15
+ inputs = tokenizer.encode_plus(user_input, context, add_special_tokens=True, return_tensors="pt")
16
+ input_ids = inputs["input_ids"].tolist()[0]
17
+ output = model(**inputs)
18
+
19
+ answer_start = torch.argmax(output.start_logits)
20
+ answer_end = torch.argmax(output.end_logits) + 1
21
+ answer = tokenizer.convert_tokens_to_string(tokenizer.convert_ids_to_tokens(input_ids[answer_start:answer_end]))
22
+ answer = answer.replace(' ', '')
23
+
24
+ st.text_area("Chatbot:", answer, height=100)
requirements.txt CHANGED
@@ -3,4 +3,5 @@ sentencepiece
3
  transformers
4
  langchain
5
  Cython
6
- torch
 
 
3
  transformers
4
  langchain
5
  Cython
6
+ torch
7
+ hugchat