fastx commited on
Commit
0445c20
·
1 Parent(s): a6bcf85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -5
app.py CHANGED
@@ -1,3 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import os
3
  import json
@@ -6,8 +43,9 @@ import requests
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 = {
@@ -91,22 +129,35 @@ def predict(inputs, top_p, temperature, openai_api_key, chat_counter, chatbot=[]
91
  def reset_textbox():
92
  return gr.update(value='')
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,5 +165,6 @@ with gr.Blocks(css = """#col_container {width: 1000px; margin-left: auto; margin
114
  b1.click(reset_textbox, [], [inputs])
115
  inputs.submit(reset_textbox, [], [inputs])
116
 
 
117
  demo.queue().launch(debug=True)
118
 
 
1
+ Hugging Face's logo
2
+ Hugging Face
3
+ Search models, datasets, users...
4
+ Models
5
+ Datasets
6
+ Spaces
7
+ Docs
8
+ Solutions
9
+ Pricing
10
+
11
+
12
+
13
+ Spaces:
14
+
15
+ zjhcr
16
+ /
17
+ ChatGPTwithAPI Copied
18
+ like
19
+ 0
20
+ App
21
+ Files and versions
22
+ Community
23
+ ChatGPTwithAPI
24
+ /
25
+ app.py
26
+ zjhcr's picture
27
+ zjhcr
28
+ Duplicate from ysharma/ChatGPTwithAPI
29
+ 659118f
30
+ about 10 hours ago
31
+ raw
32
+ history
33
+ blame
34
+ contribute
35
+ delete
36
+ No virus
37
+ 5.37 kB
38
  import gradio as gr
39
  import os
40
  import json
 
43
  #Streaming endpoint
44
  API_URL = "https://api.openai.com/v1/chat/completions" #os.getenv("API_URL") + "/generate_stream"
45
 
46
+ #Testing with my Open AI Key
47
+ #OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
48
 
 
49
  def predict(inputs, top_p, temperature, openai_api_key, chat_counter, chatbot=[], history=[]): #repetition_penalty, top_k
50
 
51
  payload = {
 
129
  def reset_textbox():
130
  return gr.update(value='')
131
 
132
+ title = """<h1 align="center">🔥ChatGPT API 🚀Streaming🚀</h1>"""
133
  description = """Language models can be conditioned to act like dialogue agents through a conversational prompt that typically takes the form:
134
+ ```
135
+ User: <utterance>
136
+ Assistant: <utterance>
137
+ User: <utterance>
138
+ Assistant: <utterance>
139
+ ...
140
+ ```
141
+ In this app, you can explore the outputs of a gpt-3.5-turbo LLM.
142
+ """
143
 
144
  with gr.Blocks(css = """#col_container {width: 1000px; margin-left: auto; margin-right: auto;}
145
  #chatbot {height: 520px; overflow: auto;}""") as demo:
146
+ gr.HTML(title)
147
+ gr.HTML('''<center><Lisa's Chatbot></center>''')
148
+ with gr.Column(elem_id = "col_container"):
149
  openai_api_key = gr.Textbox(type='password', label="Enter your OpenAI API key here")
150
  chatbot = gr.Chatbot(elem_id='chatbot') #c
151
+ inputs = gr.Textbox(placeholder= "Hi there!", label= "Type an input and press Enter") #t
152
  state = gr.State([]) #s
153
  b1 = gr.Button()
154
 
155
+ #inputs, top_p, temperature, top_k, repetition_penalty
156
  with gr.Accordion("Parameters", open=False):
157
  top_p = gr.Slider( minimum=-0, maximum=1.0, value=1.0, step=0.05, interactive=True, label="Top-p (nucleus sampling)",)
158
  temperature = gr.Slider( minimum=-0, maximum=5.0, value=1.0, step=0.1, interactive=True, label="Temperature",)
159
+ #top_k = gr.Slider( minimum=1, maximum=50, value=4, step=1, interactive=True, label="Top-k",)
160
+ #repetition_penalty = gr.Slider( minimum=0.1, maximum=3.0, value=1.03, step=0.01, interactive=True, label="Repetition Penalty", )
161
  chat_counter = gr.Number(value=0, visible=False, precision=0)
162
 
163
  inputs.submit( predict, [inputs, top_p, temperature, openai_api_key, chat_counter, chatbot, state], [chatbot, state, chat_counter],)
 
165
  b1.click(reset_textbox, [], [inputs])
166
  inputs.submit(reset_textbox, [], [inputs])
167
 
168
+ #gr.Markdown(description)
169
  demo.queue().launch(debug=True)
170