Spaces:
Build error
Build error
jh000107
commited on
Commit
·
cdc3959
1
Parent(s):
72e1144
using env file
Browse files
_.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
OPENAI_API_KEY=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
|
app.py
CHANGED
|
@@ -187,27 +187,17 @@ def get_completion(conversation, model="gpt-4-1106-preview"):
|
|
| 187 |
|
| 188 |
[{sample_output}]
|
| 189 |
"""
|
| 190 |
-
|
| 191 |
-
# load_dotenv(find_dotenv("_.env"), override=True)
|
| 192 |
-
|
| 193 |
-
openai_api_key = os.environ['OPENAI_API_KEY']
|
| 194 |
-
|
| 195 |
-
if openai_api_key is None:
|
| 196 |
-
raise ValueError("No OpenAI API key found. Please set the OPENAI_API_KEY environment variable.")
|
| 197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
# client = OpenAI()
|
| 202 |
-
|
| 203 |
-
# messages = [{"role": "user", "content": prompt}]
|
| 204 |
-
# response = client.chat.completions.create(
|
| 205 |
-
# model=model,
|
| 206 |
-
# messages=messages,
|
| 207 |
-
# temperature=0, # this is the degree of randomness of the model's output
|
| 208 |
-
# )
|
| 209 |
-
|
| 210 |
-
# analysis = response.choices[0].message.content
|
| 211 |
|
| 212 |
def extract_conv_with_labels(analysis):
|
| 213 |
analysis = analysis.replace("\n", " ")
|
|
@@ -300,10 +290,16 @@ def get_completion(conversation, model="gpt-4-1106-preview"):
|
|
| 300 |
|
| 301 |
return fig
|
| 302 |
|
| 303 |
-
|
| 304 |
|
| 305 |
-
|
| 306 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
|
| 308 |
import gradio as gr
|
| 309 |
|
|
@@ -315,7 +311,9 @@ with gr.Blocks() as gpt_analysis:
|
|
| 315 |
volunteer's perspective.<br /> Click on them and submit them to the model to see how it works.")
|
| 316 |
conversation = gr.Textbox(label="Input", lines=2)
|
| 317 |
btn = gr.Button(value="Submit")
|
| 318 |
-
|
|
|
|
|
|
|
| 319 |
with gr.Row():
|
| 320 |
output_box = gr.Textbox(value="", label="Output",lines=4)
|
| 321 |
plot_box = gr.Plot(label="Analysis Plot")
|
|
|
|
| 187 |
|
| 188 |
[{sample_output}]
|
| 189 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
+
client = OpenAI()
|
| 192 |
+
|
| 193 |
+
messages = [{"role": "user", "content": prompt}]
|
| 194 |
+
response = client.chat.completions.create(
|
| 195 |
+
model=model,
|
| 196 |
+
messages=messages,
|
| 197 |
+
temperature=0, # this is the degree of randomness of the model's output
|
| 198 |
+
)
|
| 199 |
|
| 200 |
+
analysis = response.choices[0].message.content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
def extract_conv_with_labels(analysis):
|
| 203 |
analysis = analysis.replace("\n", " ")
|
|
|
|
| 290 |
|
| 291 |
return fig
|
| 292 |
|
| 293 |
+
fig = sentiment_flow_plot(analysis)
|
| 294 |
|
| 295 |
+
return response.choices[0].message.content, fig
|
| 296 |
+
|
| 297 |
+
def set_key(key):
|
| 298 |
+
with open("_.env", "w") as file:
|
| 299 |
+
file.write(f"OPENAI_API_KEY={key}")
|
| 300 |
+
|
| 301 |
+
load_dotenv(find_dotenv("_.env"), override=True)
|
| 302 |
+
return
|
| 303 |
|
| 304 |
import gradio as gr
|
| 305 |
|
|
|
|
| 311 |
volunteer's perspective.<br /> Click on them and submit them to the model to see how it works.")
|
| 312 |
conversation = gr.Textbox(label="Input", lines=2)
|
| 313 |
btn = gr.Button(value="Submit")
|
| 314 |
+
api_key = gr.Textbox(label="Key", lines=1)
|
| 315 |
+
btn_key = gr.Button(value="Submit Key")
|
| 316 |
+
btn_key.click(set_key, inputs=api_key)
|
| 317 |
with gr.Row():
|
| 318 |
output_box = gr.Textbox(value="", label="Output",lines=4)
|
| 319 |
plot_box = gr.Plot(label="Analysis Plot")
|