fastx commited on
Commit
4f0b0a1
·
1 Parent(s): 3c97649

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -16
app.py CHANGED
@@ -6,9 +6,8 @@ import requests
6
  #Streaming endpoint
7
  API_URL = "https://api.openai.com/v1/chat/completions" #os.getenv("API_URL") + "/generate_stream"
8
 
9
- #Testing with my Open AI Key
10
- #OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
11
 
 
12
  def predict(inputs, top_p, temperature, openai_api_key, chat_counter, chatbot=[], history=[]): #repetition_penalty, top_k
13
 
14
  payload = {
@@ -94,31 +93,20 @@ def reset_textbox():
94
 
95
  title = """<h1 align="center"> ChatGPT API</h1>"""
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>
99
- Assistant: <utterance>
100
- User: <utterance>
101
- Assistant: <utterance>
102
- ...
103
- ```
104
- In this app, you can explore the outputs of a gpt-3.5-turbo LLM.
105
- """
106
 
107
  with gr.Blocks(css = """#col_container {width: 1000px; margin-left: auto; margin-right: auto;}
108
  #chatbot {height: 520px; overflow: auto;}""") as demo:
109
  with gr.Column(elem_id = "col_container"):
110
  openai_api_key = gr.Textbox(type='password', label="Enter your OpenAI API key here")
111
  chatbot = gr.Chatbot(elem_id='chatbot') #c
112
- inputs = gr.Textbox(placeholder= "Hi there!", label= "Type an input and press Enter") #t
113
  state = gr.State([]) #s
114
  b1 = gr.Button()
115
 
116
- #inputs, top_p, temperature, top_k, repetition_penalty
117
  with gr.Accordion("Parameters", open=False):
118
  top_p = gr.Slider( minimum=-0, maximum=1.0, value=1.0, step=0.05, interactive=True, label="Top-p (nucleus sampling)",)
119
  temperature = gr.Slider( minimum=-0, maximum=5.0, value=1.0, step=0.1, interactive=True, label="Temperature",)
120
- #top_k = gr.Slider( minimum=1, maximum=50, value=4, step=1, interactive=True, label="Top-k",)
121
- #repetition_penalty = gr.Slider( minimum=0.1, maximum=3.0, value=1.03, step=0.01, interactive=True, label="Repetition Penalty", )
122
  chat_counter = gr.Number(value=0, visible=False, precision=0)
123
 
124
  inputs.submit( predict, [inputs, top_p, temperature, openai_api_key, chat_counter, chatbot, state], [chatbot, state, chat_counter],)
@@ -126,6 +114,5 @@ with gr.Blocks(css = """#col_container {width: 1000px; margin-left: auto; margin
126
  b1.click(reset_textbox, [], [inputs])
127
  inputs.submit(reset_textbox, [], [inputs])
128
 
129
- #gr.Markdown(description)
130
  demo.queue().launch(debug=True)
131
 
 
6
  #Streaming endpoint
7
  API_URL = "https://api.openai.com/v1/chat/completions" #os.getenv("API_URL") + "/generate_stream"
8
 
 
 
9
 
10
+ openai_api_key = "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"
11
  def predict(inputs, top_p, temperature, openai_api_key, chat_counter, chatbot=[], history=[]): #repetition_penalty, top_k
12
 
13
  payload = {
 
93
 
94
  title = """<h1 align="center"> ChatGPT API</h1>"""
95
  description = """Language models can be conditioned to act like dialogue agents through a conversational prompt that typically takes the form:
96
+
 
 
 
 
 
 
 
 
97
 
98
  with gr.Blocks(css = """#col_container {width: 1000px; margin-left: auto; margin-right: auto;}
99
  #chatbot {height: 520px; overflow: auto;}""") as demo:
100
  with gr.Column(elem_id = "col_container"):
101
  openai_api_key = gr.Textbox(type='password', label="Enter your OpenAI API key here")
102
  chatbot = gr.Chatbot(elem_id='chatbot') #c
103
+ inputs = gr.Textbox(placeholder= "Type here!", label= "Type an input and press Enter") #t
104
  state = gr.State([]) #s
105
  b1 = gr.Button()
106
 
 
107
  with gr.Accordion("Parameters", open=False):
108
  top_p = gr.Slider( minimum=-0, maximum=1.0, value=1.0, step=0.05, interactive=True, label="Top-p (nucleus sampling)",)
109
  temperature = gr.Slider( minimum=-0, maximum=5.0, value=1.0, step=0.1, interactive=True, label="Temperature",)
 
 
110
  chat_counter = gr.Number(value=0, visible=False, precision=0)
111
 
112
  inputs.submit( predict, [inputs, top_p, temperature, openai_api_key, chat_counter, chatbot, state], [chatbot, state, chat_counter],)
 
114
  b1.click(reset_textbox, [], [inputs])
115
  inputs.submit(reset_textbox, [], [inputs])
116
 
 
117
  demo.queue().launch(debug=True)
118