ZongqianLi commited on
Commit
9288c3f
·
verified ·
1 Parent(s): 2f06227

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -37
app.py CHANGED
@@ -1,12 +1,6 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
- import streamlit as st
5
- from st_chat_message import message
6
-
7
- message("Hello world!", is_user=True)
8
- message("Hi")
9
-
10
  st.markdown("# Auto-generating Question-Answering Datasets with Domain-Specific Knowledge for Language Models in Scientific Tasks", unsafe_allow_html=True)
11
 
12
  ##########
@@ -49,34 +43,63 @@ st.write(f"Your selected model: {model}")
49
  # 加载问答模型
50
  pipe = pipeline("question-answering", model=model)
51
 
52
- st.markdown('### Input a paper: ', unsafe_allow_html=True)
53
-
54
- # 设置默认的问题和上下文
55
- default_property = "FF"
56
- default_context = "The referential DSSC with Pt CE was also measured under the same conditions, which yields η of 6.66% (Voc= 0.78 V, Jsc= 13.0 mA cm−2, FF = 65.9%)."
57
-
58
- # 获取用户输入的问题和上下文
59
- property = st.text_input("Enter your the name of the property: ", value=default_property)
60
- context = st.text_area("Enter the context: ", value=default_context, height=100)
61
-
62
- # 添加一个按钮,用户点击后执行问答
63
- if st.button('Extract the property'):
64
- question_1 = f"What is the value of {property}?"
65
- if context and question_1:
66
- out = pipe({
67
- 'question': question_1,
68
- 'context': context
69
- })
70
- value = out["answer"]
71
- st.write(f"First-turn question: {question_1}")
72
- st.write(f"First-turn answer: {value}")
73
- question_2 = f"What material has {property} of {value}?"
74
- out = pipe({
75
- 'question': question_2,
76
- 'context': context
77
- })
78
- material = out["answer"]
79
- st.write(f"Second-turn question: {question_2}")
80
- st.write(f"First-turn answer: {material}")
81
- else:
82
- st.write("Please enter both a question and context.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
 
 
 
 
 
 
4
  st.markdown("# Auto-generating Question-Answering Datasets with Domain-Specific Knowledge for Language Models in Scientific Tasks", unsafe_allow_html=True)
5
 
6
  ##########
 
43
  # 加载问答模型
44
  pipe = pipeline("question-answering", model=model)
45
 
46
+ st.markdown('### QA: ', unsafe_allow_html=True)
47
+
48
+ col1, col2 = st.columns(2)
49
+
50
+ with col1:
51
+ if st.button("Solar Cell QA Dataset"):
52
+ default_property = "FF"
53
+ default_context = "The referential DSSC with Pt CE was also measured under the same conditions, which yields η of 6.66% (Voc= 0.78 V, Jsc= 13.0 mA cm−2, FF = 65.9%)."
54
+
55
+ # 获取用户输入的问题和上下文
56
+ property = st.text_input("Enter your the name of the property: ", value=default_property)
57
+ context = st.text_area("Enter the context: ", value=default_context, height=100)
58
+
59
+ # 添加一个按钮,用户点击后执行问答
60
+ if st.button('Extract the property'):
61
+ question_1 = f"What is the value of {property}?"
62
+ if context and question_1:
63
+ out = pipe({
64
+ 'question': question_1,
65
+ 'context': context
66
+ })
67
+ value = out["answer"]
68
+ st.write(f"First-turn question: {question_1}")
69
+ st.write(f"First-turn answer: {value}")
70
+ question_2 = f"What material has {property} of {value}?"
71
+ out = pipe({
72
+ 'question': question_2,
73
+ 'context': context
74
+ })
75
+ material = out["answer"]
76
+ st.write(f"Second-turn question: {question_2}")
77
+ st.write(f"First-turn answer: {material}")
78
+ else:
79
+ st.write("Please enter both a question and context.")
80
+
81
+ with col2:
82
+ if st.button("SuAD Dataset QA"):
83
+ default_question = "To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France?"
84
+ default_context = """Architecturally, the school has a Catholic character. Atop the Main Building's gold dome is a golden statue of the Virgin Mary. Immediately in front of the Main Building and facing it, is a copper statue of Christ with arms upraised with the legend "Venite Ad Me Omnes". Next to the Main Building is the Basilica of the Sacred Heart. Immediately behind the basilica is the Grotto, a Marian place of prayer and reflection. It is a replica of the grotto at Lourdes, France where the Virgin Mary reputedly appeared to Saint Bernadette Soubirous in 1858. At the end of the main drive (and in a direct line that connects through 3 statues and the Gold Dome), is a simple, modern stone statue of Mary."""
85
+
86
+ question = st.text_input("Enter your the name of the property: ", value=default_property)
87
+ context = st.text_area("Enter the context: ", value=default_context, height=100)
88
+
89
+ # 添加一个按钮,用户点击后执行问答
90
+ if st.button('Extract the answer'):
91
+ if context and question:
92
+ out = pipe({
93
+ 'question': question,
94
+ 'context': context
95
+ })
96
+ st.write(f"Question: {question}")
97
+ st.write(f"Answer: {out["answer"]}")
98
+ else:
99
+ st.write("Please enter both a question and context.")
100
+
101
+
102
+
103
+
104
+
105
+