Spaces:
Build error
Build error
Upload 2 files
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ from utils import (
|
|
8 |
get_sgpt_embedding_model,
|
9 |
get_flan_t5_model,
|
10 |
get_t5_model,
|
|
|
11 |
)
|
12 |
|
13 |
from utils import (
|
@@ -16,8 +17,7 @@ from utils import (
|
|
16 |
format_query,
|
17 |
sentence_id_combine,
|
18 |
text_lookup,
|
19 |
-
|
20 |
-
gpt3_summary,
|
21 |
)
|
22 |
|
23 |
|
@@ -62,7 +62,7 @@ encoder_model = st.selectbox("Select Encoder Model", encoder_models_choice)
|
|
62 |
|
63 |
# Choose decoder model
|
64 |
|
65 |
-
decoder_models_choice = ["FLAN-T5", "T5", "GPT3
|
66 |
|
67 |
decoder_model = st.selectbox("Select Decoder Model", decoder_models_choice)
|
68 |
|
@@ -120,25 +120,8 @@ if decoder_model == "GPT3 (summary_davinci)":
|
|
120 |
)
|
121 |
api_key = save_key(openai_key)
|
122 |
openai.api_key = api_key
|
123 |
-
|
124 |
-
|
125 |
-
output_text.append(gpt3_summary(context_text))
|
126 |
-
generated_text = ". ".join(output_text)
|
127 |
-
st.write(gpt3_summary(generated_text))
|
128 |
-
|
129 |
-
elif decoder_model == "GPT3 (QA_davinci)":
|
130 |
-
openai_key = st.text_input(
|
131 |
-
"Enter OpenAI key",
|
132 |
-
value=st.secrets["openai_key"],
|
133 |
-
type="password",
|
134 |
-
)
|
135 |
-
api_key = save_key(openai_key)
|
136 |
-
openai.api_key = api_key
|
137 |
-
output_text = []
|
138 |
-
for context_text in context_list:
|
139 |
-
output_text.append(gpt3_qa(query_text, context_text))
|
140 |
-
generated_text = ". ".join(output_text)
|
141 |
-
st.write(gpt3_qa(query_text, generated_text))
|
142 |
|
143 |
elif decoder_model == "T5":
|
144 |
t5_pipeline = get_t5_model()
|
|
|
8 |
get_sgpt_embedding_model,
|
9 |
get_flan_t5_model,
|
10 |
get_t5_model,
|
11 |
+
save_key,
|
12 |
)
|
13 |
|
14 |
from utils import (
|
|
|
17 |
format_query,
|
18 |
sentence_id_combine,
|
19 |
text_lookup,
|
20 |
+
gpt3,
|
|
|
21 |
)
|
22 |
|
23 |
|
|
|
62 |
|
63 |
# Choose decoder model
|
64 |
|
65 |
+
decoder_models_choice = ["FLAN-T5", "T5", "GPT3 - (text-davinci-003)"]
|
66 |
|
67 |
decoder_model = st.selectbox("Select Decoder Model", decoder_models_choice)
|
68 |
|
|
|
120 |
)
|
121 |
api_key = save_key(openai_key)
|
122 |
openai.api_key = api_key
|
123 |
+
generated_text = gpt3(query_text, context_list)
|
124 |
+
st.write(gpt3(generated_text))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
elif decoder_model == "T5":
|
127 |
t5_pipeline = get_t5_model()
|
utils.py
CHANGED
@@ -113,10 +113,15 @@ def text_lookup(data, sentence_ids):
|
|
113 |
return context
|
114 |
|
115 |
|
116 |
-
def
|
117 |
response = openai.Completion.create(
|
118 |
model="text-davinci-003",
|
119 |
-
prompt=
|
|
|
|
|
|
|
|
|
|
|
120 |
temperature=0.1,
|
121 |
max_tokens=512,
|
122 |
top_p=1.0,
|
@@ -126,20 +131,6 @@ def gpt3_summary(text):
|
|
126 |
return response.choices[0].text
|
127 |
|
128 |
|
129 |
-
def gpt3_qa(query, answer):
|
130 |
-
response = openai.Completion.create(
|
131 |
-
model="text-davinci-003",
|
132 |
-
prompt="Q: " + query + "\nA: " + answer,
|
133 |
-
temperature=0,
|
134 |
-
max_tokens=512,
|
135 |
-
top_p=1,
|
136 |
-
frequency_penalty=0.0,
|
137 |
-
presence_penalty=0.0,
|
138 |
-
stop=["\n"],
|
139 |
-
)
|
140 |
-
return response.choices[0].text
|
141 |
-
|
142 |
-
|
143 |
# Transcript Retrieval
|
144 |
|
145 |
|
|
|
113 |
return context
|
114 |
|
115 |
|
116 |
+
def gpt3(query, result):
|
117 |
response = openai.Completion.create(
|
118 |
model="text-davinci-003",
|
119 |
+
prompt=f"""Context information is below. \n"
|
120 |
+
"---------------------\n"
|
121 |
+
"{result}"
|
122 |
+
"\n---------------------\n"
|
123 |
+
"Given the context information and prior knowledge, answer this question: {query}. \n"
|
124 |
+
"Try to include as many key details as possible and format the answer in points. \n" """,
|
125 |
temperature=0.1,
|
126 |
max_tokens=512,
|
127 |
top_p=1.0,
|
|
|
131 |
return response.choices[0].text
|
132 |
|
133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
# Transcript Retrieval
|
135 |
|
136 |
|