Spaces:
Sleeping
Sleeping
pax-dare-lab
commited on
Commit
•
b7012f5
1
Parent(s):
8d6eeed
First Commit
Browse files- app.py +24 -0
- requirements.txt +6 -0
app.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
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
sentencepiece
|
3 |
+
transformers
|
4 |
+
langchain
|
5 |
+
Cython
|
6 |
+
torch
|