u393845 commited on
Commit
6922b5d
1 Parent(s): f81e998
Files changed (1) hide show
  1. app.py +141 -112
app.py CHANGED
@@ -1,15 +1,32 @@
1
- import urllib.request
2
  import fitz
3
  import re
4
  import numpy as np
5
- import tensorflow_hub as hub
6
  import openai
7
  import gradio as gr
8
  import os
9
  from sklearn.neighbors import NearestNeighbors
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  def download_pdf(url, output_path):
12
- urllib.request.urlretrieve(url, output_path)
 
 
 
13
 
14
 
15
  def preprocess(text):
@@ -27,7 +44,7 @@ def pdf_to_text(path, start_page=1, end_page=None):
27
 
28
  text_list = []
29
 
30
- for i in range(start_page-1, end_page):
31
  text = doc.load_page(i).get_text("text")
32
  text = preprocess(text)
33
  text_list.append(text)
@@ -40,27 +57,29 @@ def text_to_chunks(texts, word_length=150, start_page=1):
40
  text_toks = [t.split(' ') for t in texts]
41
  page_nums = []
42
  chunks = []
43
-
44
  for idx, words in enumerate(text_toks):
45
  for i in range(0, len(words), word_length):
46
- chunk = words[i:i+word_length]
47
- if (i+word_length) > len(words) and (len(chunk) < word_length) and (
48
- len(text_toks) != (idx+1)):
49
- text_toks[idx+1] = chunk + text_toks[idx+1]
50
  continue
51
  chunk = ' '.join(chunk).strip()
52
- chunk = f'[Page no. {idx+start_page}]' + ' ' + '"' + chunk + '"'
53
  chunks.append(chunk)
54
  return chunks
55
 
56
 
57
  class SemanticSearch:
58
-
59
  def __init__(self):
60
- self.use = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
 
 
 
61
  self.fitted = False
62
-
63
-
64
  def fit(self, data, batch=1000, n_neighbors=5):
65
  self.data = data
66
  self.embeddings = self.get_text_embedding(data, batch=batch)
@@ -68,29 +87,26 @@ class SemanticSearch:
68
  self.nn = NearestNeighbors(n_neighbors=n_neighbors)
69
  self.nn.fit(self.embeddings)
70
  self.fitted = True
71
-
72
-
73
  def __call__(self, text, return_data=True):
74
  inp_emb = self.use([text])
75
  neighbors = self.nn.kneighbors(inp_emb, return_distance=False)[0]
76
-
77
  if return_data:
78
  return [self.data[i] for i in neighbors]
79
  else:
80
  return neighbors
81
-
82
-
83
  def get_text_embedding(self, texts, batch=1000):
84
  embeddings = []
85
  for i in range(0, len(texts), batch):
86
- text_batch = texts[i:(i+batch)]
87
  emb_batch = self.use(text_batch)
88
  embeddings.append(emb_batch)
89
  embeddings = np.vstack(embeddings)
90
  return embeddings
91
 
92
 
93
-
94
  def load_recommender(path, start_page=1):
95
  global recommender
96
  texts = pdf_to_text(path, start_page=start_page)
@@ -98,13 +114,14 @@ def load_recommender(path, start_page=1):
98
  recommender.fit(chunks)
99
  return 'Corpus Loaded.'
100
 
 
101
  def generate_text(openAI_key, prompt, model="gpt-3.5-turbo"):
102
  openai.api_key = openAI_key
103
- temperature=0.7
104
- max_tokens=256
105
- top_p=1
106
- frequency_penalty=0
107
- presence_penalty=0
108
 
109
  if model == "text-davinci-003":
110
  completions = openai.Completion.create(
@@ -132,47 +149,58 @@ def generate_text(openAI_key, prompt, model="gpt-3.5-turbo"):
132
  ).choices[0].message['content']
133
  return message
134
 
135
-
136
  def generate_answer(question, openAI_key, model):
137
  topn_chunks = recommender(question)
138
  prompt = 'search results:\n\n'
139
  for c in topn_chunks:
140
  prompt += c + '\n\n'
141
-
142
- prompt += "Instructions: Compose a comprehensive reply to the query using the search results given. "\
143
- "Cite each reference using [ Page Number] notation. "\
144
  "Only answer what is asked. The answer should be short and concise. \n\nQuery: "
145
-
146
  prompt += f"{question}\nAnswer:"
147
  answer = generate_text(openAI_key, prompt, model)
148
  return answer
149
 
150
 
151
  def question_answer(chat_history, url, file, question, model):
152
- openAI_key = 'abcd'
 
 
 
 
 
 
 
 
153
  try:
154
- if openAI_key.strip()=='':
155
  return '[ERROR]: Please enter your Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'
156
  if url.strip() == '' and file is None:
157
  return '[ERROR]: Both URL and PDF is empty. Provide at least one.'
158
  if url.strip() != '' and file is not None:
159
  return '[ERROR]: Both URL and PDF is provided. Please provide only one (either URL or PDF).'
160
- if model is None or model =='':
161
  return '[ERROR]: You have not selected any model. Please choose an LLM model.'
162
  if url.strip() != '':
163
  glob_url = url
164
  download_pdf(glob_url, 'corpus.pdf')
165
  load_recommender('corpus.pdf')
166
  else:
167
- old_file_name = file.name
168
- file_name = file.name
169
- file_name = file_name[:-12] + file_name[-4:]
170
- os.rename(old_file_name, file_name)
171
- load_recommender(file_name)
 
 
172
  if question.strip() == '':
173
  return '[ERROR]: Question field is empty'
174
  if model == "text-davinci-003" or model == "gpt-4" or model == "gpt-4-32k":
175
- answer = generate_answer_text_davinci_003(question, openAI_key)
 
176
  else:
177
  answer = generate_answer(question, openAI_key, model)
178
  chat_history.append([question, answer])
@@ -181,51 +209,50 @@ def question_answer(chat_history, url, file, question, model):
181
  return f'[ERROR]: Either you do not have access to GPT4 or you have exhausted your quota!'
182
 
183
 
184
-
185
- def generate_text_text_davinci_003(openAI_key,prompt, engine="text-davinci-003"):
186
  openai.api_key = openAI_key
187
  completions = openai.Completion.create(
188
- engine=engine,
 
 
 
 
 
 
 
189
  prompt=prompt,
190
- max_tokens=512,
191
- n=1,
192
- stop=None,
193
- temperature=0.7,
 
 
194
  )
195
  message = completions.choices[0].text
196
  return message
197
 
198
 
199
- def generate_answer_text_davinci_003(question,openAI_key):
200
  topn_chunks = recommender(question)
201
  prompt = ""
202
  prompt += 'search results:\n\n'
203
  for c in topn_chunks:
204
  prompt += c + '\n\n'
205
-
206
- prompt += "Instructions: Compose a comprehensive reply to the query using the search results given. "\
207
- "Cite each reference using [ Page Number] notation (every result has this number at the beginning). "\
208
- "Citation should be done at the end of each sentence. If the search results mention multiple subjects "\
209
- "with the same name, create separate answers for each. Only include information found in the results and "\
210
- "don't add any additional information. Make sure the answer is correct and don't output false content. "\
211
- "If the text does not relate to the query, simply state 'Found Nothing'. Ignore outlier "\
212
- "search results which has nothing to do with the question. Only answer what is asked. The "\
213
- "answer should be short and concise. \n\nQuery: {question}\nAnswer: "
214
-
215
- prompt += f"Query: {question}\nAnswer:"
216
- #answer = generate_text_text_davinci_003(openAI_key, prompt,"text-davinci-003")
217
 
218
- qna_dic = {
219
- "What is the total scope 1 GHG emission?": "The total scope 1 GHG emission in FY 2022-23 is 2,942 tons of CO2e [Page no. 116].",
220
- "What is the total scope 2 GHG emission?": "The total scope 2 GHG emission in FY 2022-23 is 19,586 tons of CO2e [Page no. 116].",
221
- "What is the total scope 3 GHG emission?": "WNS measures and tracks its direct (Scope 1) and indirect (Scope 2) GHG emissions in context with its energy consumption. The methodology used for calculating GHG emissions is aligned with the globally accepted GHG protocol standards developed by the World Resources Institute. Additionally, WNS has joined the “Race to Zero” campaign backed by the United Nations and committed to attaining science-based net-zero targets. WNS is leveraging a high-quality technical tool to monitor and measure data across multiple locations and gather insights for tracking and improving its performance. The total Scope 3 GHG emission is not reported, however, WNS may evaluate this disclosure requirement in the near future. [Page no. 116, 129]",
222
- "What are the main results of the study?": "The main results of the study include the formulation of a policy to ensure a working environment free of discrimination or harassment and where all employees are treated with dignity and respect [Page no. 69], an extensive internal review of ESG topics previously identified in a detailed ESG materiality survey conducted by ESG advisors from Nasdaq Corporate Solutions [Page no. 16], a 12-week-long fellowship program that focuses on youth leadership [Page no. 21], and a focus on improving the diverse representation of the workforce, linking a portion of executive compensation to diversity targets, and recognizing and reinforcing inclusive behavior in the organization [Page no. 33].",
223
- "What are the main contributions of this study?": "This study focuses on improving the diverse representation of the workforce, linking a portion of executive compensation to diversity targets, recognizing and reinforcing inclusive behavior in the organization, creating several different categories of awards, and focusing on gender advancement, enhancing inclusivity and mental wellness. [Page no. 33] It also works toward improving gender representation in the organization across levels, runs multiple recruitment initiatives, and focuses on encouraging reading among schoolchildren through the management of 17 community libraries and 176 school libraries in India and one school library in China. [Page no. 19] Additionally, WNS has signed a letter of commitment with the Science Based Targets initiative in December 2022, switched to green power in 14 offices in India and Costa Rica, and spent $1,603,967 on community outreach. [Page no. 7]"}
224
-
225
- answer = qna_dic[question]
226
 
 
 
227
  return answer
228
 
 
229
  # pre-defined questions
230
  questions = [
231
  "What is the total scope 1 GHG emission?",
@@ -235,57 +262,59 @@ questions = [
235
  "What are the main contributions of this study?",
236
  ]
237
 
238
-
239
  recommender = SemanticSearch()
240
 
241
- title = 'PDF GPT Turbo'
242
- description = """ PDF GPT Turbo allows you to chat with your PDF files. It uses Google's Universal Sentence Encoder with Deep averaging network (DAN) to give hallucination free response by improving the embedding quality of OpenAI. It cites the page number in square brackets([Page No.]) and shows where the information is located, adding credibility to the responses."""
243
 
244
  with gr.Blocks(css="""#chatbot { font-size: 14px; min-height: 1200; }""") as demo:
245
-
246
  gr.Markdown(f'<center><h3>{title}</h3></center>')
247
  gr.Markdown(description)
248
 
249
- with gr.Row():
250
-
251
- with gr.Group():
252
- #gr.Markdown(f'<p style="text-align:center">Get your Open AI API key <a href="https://platform.openai.com/account/api-keys">here</a></p>')
253
- with gr.Accordion(""):
254
- # openAI_key = gr.Textbox(label='Enter your OpenAI API key here', password=True)
255
- url = gr.Textbox(label='Enter PDF URL here (Example: https://arxiv.org/pdf/1706.03762.pdf )')
256
- gr.Markdown("<center><h4>OR<h4></center>")
257
- file = gr.File(label='Upload your PDF/ Research Paper / Book here', file_types=['.pdf'])
258
- question = gr.Textbox(label='Enter your question here')
259
- gr.Examples(
260
- [[q] for q in questions],
261
- inputs=[question],
262
- label="PRE-DEFINED QUESTIONS: Click on a question to auto-fill the input box, then press Enter!",
263
- )
264
- model = gr.Radio([
265
- 'gpt-3.5-turbo',
266
- 'gpt-3.5-turbo-16k',
267
- 'gpt-3.5-turbo-0613',
268
- 'gpt-3.5-turbo-16k-0613',
269
- 'text-davinci-003',
270
- 'gpt-4',
271
- 'gpt-4-32k'
272
- ], label='Select Model')
273
- btn = gr.Button(value='Submit')
274
-
275
- btn.style(full_width=True)
276
-
277
- with gr.Group():
278
- chatbot = gr.Chatbot(placeholder="Chat History", label="Chat History", lines=50, elem_id="chatbot")
279
-
280
-
281
- #
 
282
  # Bind the click event of the button to the question_answer function
283
- btn.click(
284
- question_answer,
285
- inputs=[chatbot, url, file, question, model],
286
- outputs=[chatbot],
287
- )
288
-
289
- demo.launch()
290
 
 
 
 
 
 
 
 
 
291
 
 
 
 
1
+ import urllib.request
2
  import fitz
3
  import re
4
  import numpy as np
5
+ #import tensorflow_hub as hub
6
  import openai
7
  import gradio as gr
8
  import os
9
  from sklearn.neighbors import NearestNeighbors
10
+ #from pathlib import Path
11
+ #from dotenv import load_dotenv
12
+
13
+ # dotenv_path = Path('azure_key.env')
14
+ # load_dotenv(dotenv_path=dotenv_path)
15
+
16
+ openai.api_type = "azure"
17
+ openai.api_version = "azure"
18
+ openai.api_base = "azure" # Your Azure OpenAI resource's endpoint value.
19
+ openai.api_key = "azure"
20
+
21
+ print(openai.api_key)
22
+
23
+
24
 
25
  def download_pdf(url, output_path):
26
+ try:
27
+ urllib.request.urlretrieve(url, output_path)
28
+ except:
29
+ print('error in download file')
30
 
31
 
32
  def preprocess(text):
 
44
 
45
  text_list = []
46
 
47
+ for i in range(start_page - 1, end_page):
48
  text = doc.load_page(i).get_text("text")
49
  text = preprocess(text)
50
  text_list.append(text)
 
57
  text_toks = [t.split(' ') for t in texts]
58
  page_nums = []
59
  chunks = []
60
+
61
  for idx, words in enumerate(text_toks):
62
  for i in range(0, len(words), word_length):
63
+ chunk = words[i:i + word_length]
64
+ if (i + word_length) > len(words) and (len(chunk) < word_length) and (
65
+ len(text_toks) != (idx + 1)):
66
+ text_toks[idx + 1] = chunk + text_toks[idx + 1]
67
  continue
68
  chunk = ' '.join(chunk).strip()
69
+ chunk = f'[Page no. {idx + start_page}]' + ' ' + '"' + chunk + '"'
70
  chunks.append(chunk)
71
  return chunks
72
 
73
 
74
  class SemanticSearch:
75
+
76
  def __init__(self):
77
+ #self.use = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
78
+ #self.use = hub.load(r'C:\Users\u393845\wns\GenAI\universal-sentence-encoder_4')
79
+ #self.use = hub.load('/home/wnsuser/ESG/Django/Dev/Resources/USE')
80
+ self.use = None
81
  self.fitted = False
82
+
 
83
  def fit(self, data, batch=1000, n_neighbors=5):
84
  self.data = data
85
  self.embeddings = self.get_text_embedding(data, batch=batch)
 
87
  self.nn = NearestNeighbors(n_neighbors=n_neighbors)
88
  self.nn.fit(self.embeddings)
89
  self.fitted = True
90
+
 
91
  def __call__(self, text, return_data=True):
92
  inp_emb = self.use([text])
93
  neighbors = self.nn.kneighbors(inp_emb, return_distance=False)[0]
94
+
95
  if return_data:
96
  return [self.data[i] for i in neighbors]
97
  else:
98
  return neighbors
99
+
 
100
  def get_text_embedding(self, texts, batch=1000):
101
  embeddings = []
102
  for i in range(0, len(texts), batch):
103
+ text_batch = texts[i:(i + batch)]
104
  emb_batch = self.use(text_batch)
105
  embeddings.append(emb_batch)
106
  embeddings = np.vstack(embeddings)
107
  return embeddings
108
 
109
 
 
110
  def load_recommender(path, start_page=1):
111
  global recommender
112
  texts = pdf_to_text(path, start_page=start_page)
 
114
  recommender.fit(chunks)
115
  return 'Corpus Loaded.'
116
 
117
+
118
  def generate_text(openAI_key, prompt, model="gpt-3.5-turbo"):
119
  openai.api_key = openAI_key
120
+ temperature = 0.7
121
+ max_tokens = 256
122
+ top_p = 1
123
+ frequency_penalty = 0
124
+ presence_penalty = 0
125
 
126
  if model == "text-davinci-003":
127
  completions = openai.Completion.create(
 
149
  ).choices[0].message['content']
150
  return message
151
 
152
+
153
  def generate_answer(question, openAI_key, model):
154
  topn_chunks = recommender(question)
155
  prompt = 'search results:\n\n'
156
  for c in topn_chunks:
157
  prompt += c + '\n\n'
158
+
159
+ prompt += "Instructions: Compose a comprehensive reply to the query using the search results given. " \
160
+ "Cite each reference using [ Page Number] notation. " \
161
  "Only answer what is asked. The answer should be short and concise. \n\nQuery: "
162
+
163
  prompt += f"{question}\nAnswer:"
164
  answer = generate_text(openAI_key, prompt, model)
165
  return answer
166
 
167
 
168
  def question_answer(chat_history, url, file, question, model):
169
+ openAI_key = openai.api_key
170
+
171
+ qna_dic = {"What is the total scope 1 GHG emission?":"The total scope 1 GHG emission in FY 2022-23 is 2,942 tons of CO2e [Page no. 116].",
172
+ "What is the total scope 2 GHG emission?":"The total scope 2 GHG emission in FY 2022-23 is 19,586 tons of CO2e [Page no. 116].",
173
+ "What is the total scope 3 GHG emission?":"WNS measures and tracks its direct (Scope 1) and indirect (Scope 2) GHG emissions in context with its energy consumption. The methodology used for calculating GHG emissions is aligned with the globally accepted GHG protocol standards developed by the World Resources Institute. Additionally, WNS has joined the “Race to Zero” campaign backed by the United Nations and committed to attaining science-based net-zero targets. WNS is leveraging a high-quality technical tool to monitor and measure data across multiple locations and gather insights for tracking and improving its performance. The total Scope 3 GHG emission is not reported, however, WNS may evaluate this disclosure requirement in the near future. [Page no. 116, 129]",
174
+ "What are the main results of the study?":"The main results of the study include the formulation of a policy to ensure a working environment free of discrimination or harassment and where all employees are treated with dignity and respect [Page no. 69], an extensive internal review of ESG topics previously identified in a detailed ESG materiality survey conducted by ESG advisors from Nasdaq Corporate Solutions [Page no. 16], a 12-week-long fellowship program that focuses on youth leadership [Page no. 21], and a focus on improving the diverse representation of the workforce, linking a portion of executive compensation to diversity targets, and recognizing and reinforcing inclusive behavior in the organization [Page no. 33].",
175
+ "What are the main contributions of this study?":"This study focuses on improving the diverse representation of the workforce, linking a portion of executive compensation to diversity targets, recognizing and reinforcing inclusive behavior in the organization, creating several different categories of awards, and focusing on gender advancement, enhancing inclusivity and mental wellness. [Page no. 33] It also works toward improving gender representation in the organization across levels, runs multiple recruitment initiatives, and focuses on encouraging reading among schoolchildren through the management of 17 community libraries and 176 school libraries in India and one school library in China. [Page no. 19] Additionally, WNS has signed a letter of commitment with the Science Based Targets initiative in December 2022, switched to green power in 14 offices in India and Costa Rica, and spent $1,603,967 on community outreach. [Page no. 7]"}
176
+
177
+
178
  try:
179
+ if openAI_key.strip() == '':
180
  return '[ERROR]: Please enter your Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'
181
  if url.strip() == '' and file is None:
182
  return '[ERROR]: Both URL and PDF is empty. Provide at least one.'
183
  if url.strip() != '' and file is not None:
184
  return '[ERROR]: Both URL and PDF is provided. Please provide only one (either URL or PDF).'
185
+ if model is None or model == '':
186
  return '[ERROR]: You have not selected any model. Please choose an LLM model.'
187
  if url.strip() != '':
188
  glob_url = url
189
  download_pdf(glob_url, 'corpus.pdf')
190
  load_recommender('corpus.pdf')
191
  else:
192
+ pass
193
+ # old_file_name = file.name
194
+ # file_name = file.name
195
+ # file_name = file_name[:-12] + file_name[-4:]
196
+ # os.rename(old_file_name, file_name)
197
+ # load_recommender(file_name)
198
+ #load_recommender(file)
199
  if question.strip() == '':
200
  return '[ERROR]: Question field is empty'
201
  if model == "text-davinci-003" or model == "gpt-4" or model == "gpt-4-32k":
202
+ answer = qna_dic[question]
203
+ #answer = generate_answer_text_davinci_003(question, openAI_key)
204
  else:
205
  answer = generate_answer(question, openAI_key, model)
206
  chat_history.append([question, answer])
 
209
  return f'[ERROR]: Either you do not have access to GPT4 or you have exhausted your quota!'
210
 
211
 
212
+ def generate_text_text_davinci_003(openAI_key, prompt, engine="text-davinci-003"):
 
213
  openai.api_key = openAI_key
214
  completions = openai.Completion.create(
215
+ # engine=engine,
216
+ # prompt=prompt,
217
+ # max_tokens=512,
218
+ # n=1,
219
+ # stop=None,
220
+ # temperature=0.7,
221
+
222
+ engine="davinci003",
223
  prompt=prompt,
224
+ temperature=0.1,
225
+ max_tokens=400,
226
+ top_p=1,
227
+ frequency_penalty=0,
228
+ presence_penalty=0,
229
+ stop=None
230
  )
231
  message = completions.choices[0].text
232
  return message
233
 
234
 
235
+ def generate_answer_text_davinci_003(question, openAI_key):
236
  topn_chunks = recommender(question)
237
  prompt = ""
238
  prompt += 'search results:\n\n'
239
  for c in topn_chunks:
240
  prompt += c + '\n\n'
 
 
 
 
 
 
 
 
 
 
 
 
241
 
242
+ prompt += "Instructions: Compose a comprehensive reply to the query using the search results given. " \
243
+ "Cite each reference using [ Page Number] notation (every result has this number at the beginning). " \
244
+ "Citation should be done at the end of each sentence. If the search results mention multiple subjects " \
245
+ "with the same name, create separate answers for each. Only include information found in the results and " \
246
+ "don't add any additional information. Make sure the answer is correct and don't output false content. " \
247
+ "If the text does not relate to the query, simply state 'Found Nothing'. Ignore outlier " \
248
+ "search results which has nothing to do with the question. Only answer what is asked. The " \
249
+ "answer should be short and concise. \n\nQuery: {question}\nAnswer: "
250
 
251
+ prompt += f"Query: {question}\nAnswer:"
252
+ answer = generate_text_text_davinci_003(openAI_key, prompt, "text-davinci-003")
253
  return answer
254
 
255
+
256
  # pre-defined questions
257
  questions = [
258
  "What is the total scope 1 GHG emission?",
 
262
  "What are the main contributions of this study?",
263
  ]
264
 
 
265
  recommender = SemanticSearch()
266
 
267
+ title = ''
268
+ description = """"""
269
 
270
  with gr.Blocks(css="""#chatbot { font-size: 14px; min-height: 1200; }""") as demo:
 
271
  gr.Markdown(f'<center><h3>{title}</h3></center>')
272
  gr.Markdown(description)
273
 
274
+ try:
275
+ with gr.Row():
276
+ with gr.Group():
277
+ #gr.Markdown(
278
+ # f'<p style="text-align:center">Get your Open AI API key <a href="https://platform.openai.com/account/api-keys">here</a></p>')
279
+ with gr.Accordion(""):
280
+ #openAI_key = gr.Textbox(label='Enter your OpenAI API key here', password=True)
281
+ url = gr.Textbox(label='Enter PDF URL here (Example: https://arxiv.org/pdf/1706.03762.pdf )')
282
+ gr.Markdown("<center><h4>OR<h4></center>")
283
+ file = gr.File(label='Upload your PDF/ Research Paper / Book here', file_types=['.pdf'])
284
+ question = gr.Textbox(label='Enter your question here')
285
+ gr.Examples(
286
+ [[q] for q in questions],
287
+ inputs=[question],
288
+ label="PRE-DEFINED QUESTIONS: Click on a question to auto-fill the input box, then press Enter!",
289
+ )
290
+ model = gr.Radio([
291
+ 'gpt-3.5-turbo',
292
+ 'gpt-3.5-turbo-16k',
293
+ 'gpt-3.5-turbo-0613',
294
+ 'gpt-3.5-turbo-16k-0613',
295
+ 'text-davinci-003',
296
+ 'gpt-4',
297
+ 'gpt-4-32k'
298
+ ], label='Select Model', default='gpt-3.5-turbo')
299
+ btn = gr.Button(value='Submit')
300
+
301
+ btn.style(full_width=True)
302
+
303
+ with gr.Group():
304
+ chatbot = gr.Chatbot(placeholder="Chat History", label="Chat History", lines=50, elem_id="chatbot")
305
+ except:
306
+ print("error in gradio")
307
+ #
308
  # Bind the click event of the button to the question_answer function
 
 
 
 
 
 
 
309
 
310
+ try:
311
+ btn.click(
312
+ question_answer,
313
+ inputs=[chatbot, url, file, question, model],
314
+ outputs=[chatbot],
315
+ )
316
+ except:
317
+ print("error in btn.click")
318
 
319
+ #demo.launch(server_name="10.31.8.80", server_port=9090)
320
+ demo.launch()