bhaskartripathi commited on
Commit
31b1c13
·
verified ·
1 Parent(s): f774c84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -20
app.py CHANGED
@@ -102,11 +102,11 @@ def load_recommender(path, start_page=1):
102
 
103
  def generate_text(openAI_key, prompt, model="gpt-3.5-turbo"):
104
  openai.api_key = openAI_key
105
- temperature=0.7
106
- max_tokens=256
107
- top_p=1
108
- frequency_penalty=0
109
- presence_penalty=0
110
 
111
  if model == "text-davinci-003":
112
  completions = openai.Completion.create(
@@ -119,19 +119,19 @@ def generate_text(openAI_key, prompt, model="gpt-3.5-turbo"):
119
  )
120
  message = completions.choices[0].text
121
  else:
122
- message = openai.ChatCompletion.create(
123
  model=model,
124
  messages=[
125
  {"role": "system", "content": "You are a helpful assistant."},
126
- {"role": "assistant", "content": "Here is some initial assistant message."},
127
  {"role": "user", "content": prompt}
128
  ],
129
- temperature=.3,
130
  max_tokens=max_tokens,
131
  top_p=top_p,
132
  frequency_penalty=frequency_penalty,
133
  presence_penalty=presence_penalty,
134
- ).choices[0].message['content']
 
135
  return message
136
 
137
 
@@ -248,23 +248,19 @@ with gr.Blocks(css="""#chatbot { font-size: 14px; min-height: 1200; }""") as dem
248
  # API Key and File Inputs
249
  with gr.Accordion("API Key and PDF"):
250
  openAI_key = gr.Textbox(label='Enter your OpenAI API key here', type='password')
251
- url = gr.Textbox(label='Enter PDF URL here (Example: https://arxiv.org/pdf/1706.03762.pdf)')
252
  gr.Markdown("<center><h4>OR<h4></center>")
253
  file = gr.File(label='Upload your PDF/Research Paper/Book here', file_types=['.pdf'])
254
 
255
  # Model Selection
256
  model = gr.Radio(
257
  choices=[
258
- 'gpt-3.5-turbo',
259
- 'gpt-3.5-turbo-16k',
260
- 'gpt-3.5-turbo-0613',
261
- 'gpt-3.5-turbo-16k-0613',
262
- 'text-davinci-003',
263
  'gpt-4',
264
- 'gpt-4-32k'
265
  ],
266
  label='Select Model',
267
- value='gpt-3.5-turbo'
268
  )
269
 
270
  # Chat Interface
@@ -333,6 +329,4 @@ with gr.Blocks(css="""#chatbot { font-size: 14px; min-height: 1200; }""") as dem
333
  [msg, chatbot]
334
  )
335
 
336
- demo.launch()
337
-
338
-
 
102
 
103
  def generate_text(openAI_key, prompt, model="gpt-3.5-turbo"):
104
  openai.api_key = openAI_key
105
+ temperature = 0.1
106
+ max_tokens = 256
107
+ top_p = 1
108
+ frequency_penalty = 0
109
+ presence_penalty = 0
110
 
111
  if model == "text-davinci-003":
112
  completions = openai.Completion.create(
 
119
  )
120
  message = completions.choices[0].text
121
  else:
122
+ response = openai.ChatCompletion.create(
123
  model=model,
124
  messages=[
125
  {"role": "system", "content": "You are a helpful assistant."},
 
126
  {"role": "user", "content": prompt}
127
  ],
128
+ temperature=temperature,
129
  max_tokens=max_tokens,
130
  top_p=top_p,
131
  frequency_penalty=frequency_penalty,
132
  presence_penalty=presence_penalty,
133
+ )
134
+ message = response['choices'][0]['message']['content']
135
  return message
136
 
137
 
 
248
  # API Key and File Inputs
249
  with gr.Accordion("API Key and PDF"):
250
  openAI_key = gr.Textbox(label='Enter your OpenAI API key here', type='password')
251
+ url = gr.Textbox(label='Enter PDF URL here (Example: https://arxiv.org/pdf/1706.03762.pdf ; https://link.springer.com/content/pdf/10.1007/s10614-022-10325-8.pdf)')
252
  gr.Markdown("<center><h4>OR<h4></center>")
253
  file = gr.File(label='Upload your PDF/Research Paper/Book here', file_types=['.pdf'])
254
 
255
  # Model Selection
256
  model = gr.Radio(
257
  choices=[
258
+ 'gpt-4o-mini',
259
+ 'gpt-4o',
 
 
 
260
  'gpt-4',
 
261
  ],
262
  label='Select Model',
263
+ value='gpt-4o-mini'
264
  )
265
 
266
  # Chat Interface
 
329
  [msg, chatbot]
330
  )
331
 
332
+ demo.launch()