Spaces:
Runtime error
Runtime error
stevengrove
commited on
Commit
•
5f71fb3
1
Parent(s):
55ca90b
add api key input
Browse files
app.py
CHANGED
@@ -101,7 +101,10 @@ def postprocess(input_txt, output_txt_list):
|
|
101 |
return '\n'.join(results)
|
102 |
|
103 |
|
104 |
-
def filter(pos_tags, neg_tags, input_txt):
|
|
|
|
|
|
|
105 |
input_txt_list = preprocess(input_txt)
|
106 |
output_txt_list = []
|
107 |
for txt in input_txt_list:
|
@@ -118,6 +121,12 @@ if __name__ == '__main__':
|
|
118 |
with gr.Blocks() as demo:
|
119 |
with gr.Row():
|
120 |
with gr.Column(scale=0.3):
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
with gr.Row():
|
122 |
pos_txt = gr.Textbox(
|
123 |
lines=2,
|
@@ -148,7 +157,7 @@ if __name__ == '__main__':
|
|
148 |
output_txt = output_txt.style(height=690)
|
149 |
submit.click(
|
150 |
filter,
|
151 |
-
[pos_txt, neg_txt, input_txt],
|
152 |
[output_txt])
|
153 |
clear.click(
|
154 |
lambda: ['', '', ''],
|
|
|
101 |
return '\n'.join(results)
|
102 |
|
103 |
|
104 |
+
def filter(api_key, pos_tags, neg_tags, input_txt):
|
105 |
+
if api_key is None or api_key == '':
|
106 |
+
return 'OPENAI API Key is not set.'
|
107 |
+
openai.api_key = api_key
|
108 |
input_txt_list = preprocess(input_txt)
|
109 |
output_txt_list = []
|
110 |
for txt in input_txt_list:
|
|
|
121 |
with gr.Blocks() as demo:
|
122 |
with gr.Row():
|
123 |
with gr.Column(scale=0.3):
|
124 |
+
with gr.Row():
|
125 |
+
api_key = gr.Textbox(
|
126 |
+
lines=1,
|
127 |
+
label='OPENAI API Key',
|
128 |
+
elem_id='api_key_textbox',
|
129 |
+
placeholder='Enter your OPENAI API Key')
|
130 |
with gr.Row():
|
131 |
pos_txt = gr.Textbox(
|
132 |
lines=2,
|
|
|
157 |
output_txt = output_txt.style(height=690)
|
158 |
submit.click(
|
159 |
filter,
|
160 |
+
[api_key, pos_txt, neg_txt, input_txt],
|
161 |
[output_txt])
|
162 |
clear.click(
|
163 |
lambda: ['', '', ''],
|