SolarCellBERT / app.py
ZongqianLi's picture
Update app.py
c007f22 verified
raw
history blame
1.42 kB
import streamlit as st
from transformers import pipeline
# 定义模型配置选项
size_lst = ["-base", "-large"]
cased_lst = ["-cased", "-uncased"]
fpretrain_lst = ["None", "-scsmall", "-scmedium", "-sclarge"]
finetune_lst = ["-squad", "-scqa1", "-scqa2"]
# 为每个选项创建下拉菜单
size = st.selectbox("Choose a model size:", size_lst)
cased = st.selectbox("Whether distinguish upper and lowercase letters:", cased_lst)
fpretrain = st.selectbox("Further pretrained on a solar cell corpus:", fpretrain_lst)
finetune = st.selectbox("Finetuned on a QA dataset:", finetune_lst)
# 根据选择构建模型名称
if fpretrain == "None":
model = "".join(["ZongqianLi/bert", size, cased, finetune])
else:
model = "".join(["ZongqianLi/bert", size, cased, fpretrain, finetune])
# 显示用户选择的模型
st.write(f"Your selected model: {model}")
# 加载问答模型
pipe = pipeline("question-answering", model=model)
# 获取用户输入的问题和上下文
question = st.text_input("Enter your question here")
context = st.text_area("Enter the context here")
# 添加一个按钮,用户点击后执行问答
if st.button('Answer the Question'):
progress_bar = st.progress(0)
if context and question:
out = pipe({
'question': question,
'context': context
})
st.json(out)
else:
st.write("Please enter both a question and context.")