Spaces:
Build error
Build error
Minh Q. Le
commited on
Commit
·
2958d01
1
Parent(s):
df89157
Updated GPT UI
Browse files- app/gpt_view.py +35 -10
- main.py +1 -1
app/gpt_view.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
from openai import OpenAI
|
|
|
|
|
|
|
|
|
|
| 4 |
from app.utils import (
|
| 5 |
format_prediction_ouptut,
|
| 6 |
create_input_instruction,
|
|
@@ -249,14 +252,36 @@ def set_key(key):
|
|
| 249 |
def gpt_ui():
|
| 250 |
with gr.Blocks() as gpt_model:
|
| 251 |
gr.Markdown("# GPT 4.0")
|
| 252 |
-
gr.
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
|
| 261 |
create_input_instruction()
|
| 262 |
with gr.Row():
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import seaborn as sns
|
| 3 |
from openai import OpenAI
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import re
|
| 6 |
+
import matplotlib.pyplot as plt
|
| 7 |
from app.utils import (
|
| 8 |
format_prediction_ouptut,
|
| 9 |
create_input_instruction,
|
|
|
|
| 252 |
def gpt_ui():
|
| 253 |
with gr.Blocks() as gpt_model:
|
| 254 |
gr.Markdown("# GPT 4.0")
|
| 255 |
+
with gr.Row():
|
| 256 |
+
with gr.Column(scale=3):
|
| 257 |
+
gr.Markdown(
|
| 258 |
+
"""Another approach to analyze and predict the sentiment labels for each
|
| 259 |
+
message in a conversation is to utilize the power of GPT as a Large Language
|
| 260 |
+
Model. As of December 2023, GPT 4.0 is the latest version of GPT under the
|
| 261 |
+
name `gpt-4-1106-preview`, and it is connected with the app through Python's
|
| 262 |
+
`openai` module.
|
| 263 |
+
|
| 264 |
+
One advantage of GPT over COSMIC is that it can also generate a
|
| 265 |
+
summary for the conversation beside the sentiment labels. However,
|
| 266 |
+
the trade-off is that GPT is not free to use. With
|
| 267 |
+
`gpt-4-1106-preview` model, the pricing is $0.01/1,000 input tokens
|
| 268 |
+
and $0.03/1,000 output tokens.
|
| 269 |
+
|
| 270 |
+
Before running the model, please log in with your OpenAI's API key first.
|
| 271 |
+
The key can be created with OpenAI
|
| 272 |
+
[here](https://platform.openai.com/api-keys). Make sure to save your API key
|
| 273 |
+
in a secured file for future use.
|
| 274 |
+
"""
|
| 275 |
+
)
|
| 276 |
+
with gr.Column(scale=1):
|
| 277 |
+
api_key = gr.Textbox(
|
| 278 |
+
label="OpenAI's API key",
|
| 279 |
+
lines=1,
|
| 280 |
+
type="password",
|
| 281 |
+
placeholder="Please enter you API key here",
|
| 282 |
+
)
|
| 283 |
+
btn_key = gr.Button(value="Submit Key")
|
| 284 |
+
btn_key.click(set_key, inputs=api_key)
|
| 285 |
|
| 286 |
create_input_instruction()
|
| 287 |
with gr.Row():
|
main.py
CHANGED
|
@@ -8,7 +8,7 @@ from app import cosmic_view, gpt_view
|
|
| 8 |
|
| 9 |
cosmic_model = cosmic_view.cosmic_ui()
|
| 10 |
gpt_model = gpt_view.gpt_ui()
|
| 11 |
-
demo = gr.TabbedInterface([cosmic_model, gpt_model], ["COSMIC", "GPT
|
| 12 |
|
| 13 |
if __name__ == "__main__":
|
| 14 |
demo.launch()
|
|
|
|
| 8 |
|
| 9 |
cosmic_model = cosmic_view.cosmic_ui()
|
| 10 |
gpt_model = gpt_view.gpt_ui()
|
| 11 |
+
demo = gr.TabbedInterface([cosmic_model, gpt_model], ["COSMIC", "GPT"])
|
| 12 |
|
| 13 |
if __name__ == "__main__":
|
| 14 |
demo.launch()
|