Spaces:
Sleeping
Sleeping
Add model selection
Browse files
app.py
CHANGED
|
@@ -9,7 +9,15 @@ API_URL = "https://api.openai.com/v1/chat/completions" #os.getenv("API_URL") + "
|
|
| 9 |
#Testing with my Open AI Key
|
| 10 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
payload = {
|
| 15 |
"model": "gpt-3.5-turbo",
|
|
@@ -45,7 +53,7 @@ def predict(inputs, top_p, temperature, openai_api_key, chat_counter, chatbot=[]
|
|
| 45 |
messages.append(temp3)
|
| 46 |
#messages
|
| 47 |
payload = {
|
| 48 |
-
"model":
|
| 49 |
"messages": messages, #[{"role": "user", "content": f"{inputs}"}],
|
| 50 |
"temperature" : temperature, #1.0,
|
| 51 |
"top_p": top_p, #1.0,
|
|
@@ -92,7 +100,7 @@ def predict(inputs, top_p, temperature, openai_api_key, chat_counter, chatbot=[]
|
|
| 92 |
def reset_textbox():
|
| 93 |
return gr.update(value='')
|
| 94 |
|
| 95 |
-
title = """<h1 align="center">
|
| 96 |
description = """Language models can be conditioned to act like dialogue agents through a conversational prompt that typically takes the form:
|
| 97 |
```
|
| 98 |
User: <utterance>
|
|
@@ -109,6 +117,7 @@ with gr.Blocks(css = """#col_container {width: 1000px; margin-left: auto; margin
|
|
| 109 |
gr.HTML(title)
|
| 110 |
with gr.Column(elem_id = "col_container"):
|
| 111 |
openai_api_key = gr.Textbox(type='password', label="Enter your OpenAI API key here", value=OPENAI_API_KEY)
|
|
|
|
| 112 |
chatbot = gr.Chatbot(elem_id='chatbot') #c
|
| 113 |
inputs = gr.Textbox(placeholder= "Type here!", label= "Type an input and press Enter") #t
|
| 114 |
state = gr.State([]) #s
|
|
@@ -122,8 +131,8 @@ with gr.Blocks(css = """#col_container {width: 1000px; margin-left: auto; margin
|
|
| 122 |
#repetition_penalty = gr.Slider( minimum=0.1, maximum=3.0, value=1.03, step=0.01, interactive=True, label="Repetition Penalty", )
|
| 123 |
chat_counter = gr.Number(value=0, visible=False, precision=0)
|
| 124 |
|
| 125 |
-
inputs.submit( predict, [inputs, top_p, temperature, openai_api_key, chat_counter, chatbot, state], [chatbot, state, chat_counter],)
|
| 126 |
-
b1.click( predict, [inputs, top_p, temperature, openai_api_key, chat_counter, chatbot, state], [chatbot, state, chat_counter],)
|
| 127 |
b1.click(reset_textbox, [], [inputs])
|
| 128 |
inputs.submit(reset_textbox, [], [inputs])
|
| 129 |
|
|
|
|
| 9 |
#Testing with my Open AI Key
|
| 10 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 11 |
|
| 12 |
+
MODELS = [
|
| 13 |
+
'gpt-4o',
|
| 14 |
+
'gpt-4o-mini',
|
| 15 |
+
'gpt-4-turbo',
|
| 16 |
+
'gpt-4',
|
| 17 |
+
'gpt-3.5-turbo',
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
def predict(model_name, inputs, top_p, temperature, openai_api_key, chat_counter, chatbot=[], history=[]): #repetition_penalty, top_k
|
| 21 |
|
| 22 |
payload = {
|
| 23 |
"model": "gpt-3.5-turbo",
|
|
|
|
| 53 |
messages.append(temp3)
|
| 54 |
#messages
|
| 55 |
payload = {
|
| 56 |
+
"model": model_name,
|
| 57 |
"messages": messages, #[{"role": "user", "content": f"{inputs}"}],
|
| 58 |
"temperature" : temperature, #1.0,
|
| 59 |
"top_p": top_p, #1.0,
|
|
|
|
| 100 |
def reset_textbox():
|
| 101 |
return gr.update(value='')
|
| 102 |
|
| 103 |
+
title = """<h1 align="center">GPT-4 via API</h1>"""
|
| 104 |
description = """Language models can be conditioned to act like dialogue agents through a conversational prompt that typically takes the form:
|
| 105 |
```
|
| 106 |
User: <utterance>
|
|
|
|
| 117 |
gr.HTML(title)
|
| 118 |
with gr.Column(elem_id = "col_container"):
|
| 119 |
openai_api_key = gr.Textbox(type='password', label="Enter your OpenAI API key here", value=OPENAI_API_KEY)
|
| 120 |
+
model_name = gr.Dropdown(choices=MODELS, value=MODELS[0], allow_custom_value=True)
|
| 121 |
chatbot = gr.Chatbot(elem_id='chatbot') #c
|
| 122 |
inputs = gr.Textbox(placeholder= "Type here!", label= "Type an input and press Enter") #t
|
| 123 |
state = gr.State([]) #s
|
|
|
|
| 131 |
#repetition_penalty = gr.Slider( minimum=0.1, maximum=3.0, value=1.03, step=0.01, interactive=True, label="Repetition Penalty", )
|
| 132 |
chat_counter = gr.Number(value=0, visible=False, precision=0)
|
| 133 |
|
| 134 |
+
inputs.submit( predict, [model_name, inputs, top_p, temperature, openai_api_key, chat_counter, chatbot, state], [chatbot, state, chat_counter],)
|
| 135 |
+
b1.click( predict, [model_name, inputs, top_p, temperature, openai_api_key, chat_counter, chatbot, state], [chatbot, state, chat_counter],)
|
| 136 |
b1.click(reset_textbox, [], [inputs])
|
| 137 |
inputs.submit(reset_textbox, [], [inputs])
|
| 138 |
|