DebayanDaw commited on
Commit
e71e760
·
1 Parent(s): aea603d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -146
app.py CHANGED
@@ -159,137 +159,41 @@ busi_chunks = text_to_chunks(busi_texts, start_page=start_page)
159
 
160
 
161
 
162
- #def struct_answer(openAI_key, engine, message, dataframe, user_question):
163
- #
164
- # def generate_text2(openAI_key, engine, message):
165
- # openai.api_key = openAI_key
166
- #
167
- # completions = openai.ChatCompletion.create(
168
- # model=engine,
169
- # messages=message,
170
- # max_tokens=512,
171
- # n=1,
172
- # stop=None,
173
- # temperature=0.7,
174
- # )
175
- # message = completions.choices[0].message['content']
176
- # return message
177
- #
178
- # def filter_dataframe(openAI_key,engine, message,df=dataframe):
179
- # out_state_year = generate_text2(openAI_key, engine, message)
180
- # out_state_year = eval(out_state_year)
181
- # state= [out_state_year[1]]
182
- # year = [out_state_year[0]]
183
- # tax_type = [out_state_year[2]]
184
- # print(out_state_year)
185
- # filter_df = df[(df['Year'].isin(year)) & (df['State'].isin(state)) & (df['SubSubCategory'].isin(tax_type))].reset_index().drop('index',axis=1)
186
- # feeded_df = filter_df.loc[:,['Country','State','Govt_Type','Year','SubSubCategory',"Tax Amount",'Unit']]
187
- # feeded_df = feeded_df.rename({'Govt_Type':'Government Type','SubSubCategory':'Type of Tax','Tax Amount':'Tax Amount Collected'},axis=1)
188
- #
189
- # return feeded_df
190
- #
191
- # feeded_df = filter_dataframe(openAI_key, engine, message)
192
- # print(feeded_df.shape)
193
- #
194
- # def dataframe_to_text(new_dataframe= feeded_df):
195
- # new_dataframe.to_csv(r'nmdata.txt', index=None, sep='|', mode='a')
196
- # text_file = open('nmdata.txt', 'r')
197
- # lines = text_file.readlines()
198
- # os.remove("nmdata.txt")
199
- # return lines
200
- #
201
- # def prompt_generation(x=dataframe_to_text(), y= user_question):
202
- # prompt = ""
203
- # for line in x:
204
- # prompt+=line +'\n'
205
- # prompt += '''Take above datapoint(s) as reference and answer the following question: {0}.\n Instructions while answering the question: 1. Do not generate any additional information on your own \n
206
- # 2. Do not do generate any number on your own. Just the number mentioned in the datapoint(s) \n
207
- # 3. Take your time to understand the question and than only answer the question \n
208
- # 4. Write answer in the form of sentence. '''.format(y)
209
- # return prompt
210
- #
211
- # def generate_text(openAI_key,prompt, engine="text-davinci-003"):
212
- # openai.api_key = openAI_key
213
- # completions = openai.Completion.create(
214
- # engine=engine,
215
- # prompt=prompt,
216
- # max_tokens=512,
217
- # n=1,
218
- # stop=None,
219
- # temperature=0
220
- # )
221
- # message = completions.choices[0].text
222
- # return message
223
- #
224
- # prompt_ = prompt_generation()
225
- # response_ = generate_text(openAI_key, prompt_)
226
- # return response_
227
 
228
  def output_generation(typed_ques):
229
-
230
- type_of_query= classify_chatgpt(typed_ques, openAI_key)
231
- global recommender
232
- #print(type_of_query)
233
-
234
- if type_of_query in ['Individual Taxation Query','Individual Taxation Query.']:
235
 
236
- recommender = SemanticSearch(data=indi_chunks,loaded_array = indi_loaded_array)
237
- out_pu = question_answer(question= typed_ques, openAI_key= openAI_key)
238
- #print(out_pu)
239
  return out_pu, type_of_query
240
- elif type_of_query in ['Business Taxation Query','Business Taxation Query.']:
241
- recommender = SemanticSearch(data=busi_chunks, loaded_array=busi_loaded_array)
242
- out_pu = question_answer(question= typed_ques, openAI_key= openAI_key)
243
- #print(out_pu)
244
  return out_pu, type_of_query
245
- #elif type_of_query in ['Data Related Query', 'Data Related Query.']:
246
- #
247
- # engine="gpt-3.5-turbo-0301"
248
- # message = [{'role': 'system', 'content': '''From the provided sentence extract out the year mentioned in the sentence, State and type of Tax for which user is asking the question about.
249
- #
250
- # Instructions:
251
- # 1. Provide your output just a list in which first element is Year and second element is the State for example: [2018, "Queensland", "Land Tax"]
252
- # 2. If multiple states and year are mentioned than provide both as the result. for example: [[2018,2020], ["New South Wales","Queensland"], ["Land Tax","Gift Tax"]]
253
- # 3. Extract the exact name of the tax from the mentioned list of type of taxes below. For example, if in query motor tax is present but in the given below categories there is no category as 'motor tax' than classify into its most nearest category which has information about total tax present.
254
- # 4. Do not explain your answer. Just write the answer as mentioned in the first instruction.
255
- #
256
- # There are total 7 states in country Australia and they are as follows:
257
- # 1. Northern Territory
258
- # 2. Tasmania
259
- # 3. South Australia
260
- # 4. Western Australia
261
- # 5. Queensland
262
- # 6. Victoria
263
- # 7. New South Wales
264
- #
265
- # Classify the State from above 7 names but in case, if in the sentence none of the states are mentioned than classify from the below special cases:
266
- # 1. Give "Australia" as the result if nothing is mentioned at all.
267
- # 2. Give "All States" as the result if the sentence is talking about all the states of Australia or all the state governments of Australia.
268
- # 3. Give "Australian Capital Territory" as the result if the sentence is talking about the Australian Capitals territory.
269
- #
270
- #
271
- # Also from the sentence classify the type of tax for which user is talking about from the below list of Tax Type:
272
- # 1. Taxes on employers payroll and labour force, 2. Land taxes, 3. Municipal rates, 4. Other taxes on property, 5. Total taxes on immovable property, 6. Estate, inheritance and gift taxes,
273
- # 7. Total taxes on property, 8. Excises and levies, 9. Taxes on government lotteries, 10. Taxes on private lotteries, 11. Taxes on gambling machines, 12. Casino taxes,
274
- # 13. Race and other sports betting taxes, 14. Other taxes on gambling, 15. Total taxes on gambling, 16. Insurance companies contributions to fire brigades,
275
- # 17. Third party insurance taxes, 18. Other taxes on insurance, 19. Total taxes on insurance, 20. Government borrowing guarantee levies, 21. Stamp duties on conveyances,
276
- # 22. Other taxes on financial and capital transactions, 23. Total taxes on financial and capital transactions, 24. Total taxes on the provision of goods and services,
277
- # 25. Stamp duty on vehicle registration, 26. Other motor vehicle taxes, 27. Total motor vehicle taxes, 28. Franchise taxes, 29. Other taxes on use of goods and performance of activities,
278
- # 30. Total taxes on use of goods and performance of activities, 31. Total Taxation Northern Territory State and Local Government, 32. Taxes received from public corporations,
279
- # 33. Taxes received from other levels of government, 34. Total Taxation Tasmania State and Local Government, 35. Total Taxation South Australia State and Local Government,
280
- # 36. Total Taxation Western Australia State and Local Government, 37. Total Taxation Queensland State and Local Government, 38. Total Taxation Victoria State and Local Government,
281
- # 39. Total Taxation New South Wales State and Local Government, 40. Total Taxation Australian Capital Territory State Government, 41. Personal income tax, 42. Government health insurance levy,
282
- # 43. Fringe benefits tax, 44. Other income tax levied on individuals, 45. Total income taxes levied on individuals, 46. Company income tax, 47. Income tax paid by superannuation funds,
283
- # 48. Other income tax levied on enterprises, 49. Total income taxes levied on enterprises, 50. Dividend withholding tax, 51. Interest withholding tax, 52. Other income taxes levied on non-residents,
284
- # 53. Total income taxes levied on non-residents, 54. Total taxes on income, 55. General taxes (sales taxes), 56. Goods and services tax (GST),
285
- # 57. Crude oil and LPG, 58. Other excises, 59. Agricultural production taxes, 60. Levies on statutory corporations, 61. Total excises and levies, 62. Taxes on international trade,
286
- # 63. Taxes on financial and capital transactions, 64. Taxes on the use of goods and performance of activities, 65. Total Taxation on Commonwealth Government'''},
287
- # {'role': 'user', 'content': typed_ques}]
288
- # output_ = struct_answer(openAI_key, engine, message, ndf, typed_ques).lstrip()
289
- # #print(output_)
290
- # return output_, type_of_query
291
-
292
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293
 
294
  title = 'CDI Citizen Intelligence 360 Tool: Tax Advisory'
295
  #description = """ Citizen Intelligence 360 sources data from various government agencies and makes it accessible to citizens in a user-friendly format. This can help citizens better understand how their local government works and stay informed about important initiatives and changes in their communities. Citizen Intelligence 360 is a citizen intelligence tool that uses mapping technology to provide citizens with access to government data, performance report and other civic information. It helps to increase transparency and accountability in local government, and empowers citizens to make informed decisions and participate in the democratic process."""
@@ -306,29 +210,14 @@ def gradio_chatbox(input,history):
306
  history = history or []
307
 
308
  typed_ques = input
309
-
310
-
311
- def output(answe):
312
- ccc = "{0}".format(answe)
313
- output = ccc
314
- history.append((input,output))
315
- #print(history)
316
- return history, history
317
-
318
- if typed_ques == "Hello" :
319
- answe = "Do you have myGovID or wnat to continue as Guest."
320
- output(answe)
321
-
322
- elif typed_ques == "I have myGovID":
323
- answe = "Hi User, Please Enter Username"
324
- output(answe)
325
- else:
326
- answe = "Hi "+ typed_ques + ", Please Enter Password"
327
- output(answe)
328
-
329
  answe, query_type = output_generation(typed_ques)
330
 
331
- return output(answe)
 
 
 
 
332
 
333
 
334
 
 
159
 
160
 
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
 
163
  def output_generation(typed_ques):
164
+
165
+ type_of_query = 'dummy'
166
+
167
+ if typed_ques == "Hello" :
168
+ answe = "Do you have myGovID or wnat to continue as Guest."
169
+ return out_pu, type_of_query
170
 
171
+ elif typed_ques == "I have myGovID":
172
+ answe = "Hi User, Please Enter Username"
 
173
  return out_pu, type_of_query
174
+
175
+ elif typed_ques:
176
+ answe = "Hi "+ typed_ques + ", Please Enter Password"
 
177
  return out_pu, type_of_query
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
 
179
+ else:
180
+
181
+ type_of_query= classify_chatgpt(typed_ques, openAI_key)
182
+ global recommender
183
+ #print(type_of_query)
184
+
185
+ if type_of_query in ['Individual Taxation Query','Individual Taxation Query.']:
186
+
187
+ recommender = SemanticSearch(data=indi_chunks,loaded_array = indi_loaded_array)
188
+ out_pu = question_answer(question= typed_ques, openAI_key= openAI_key)
189
+ #print(out_pu)
190
+ return out_pu, type_of_query
191
+ elif type_of_query in ['Business Taxation Query','Business Taxation Query.']:
192
+ recommender = SemanticSearch(data=busi_chunks, loaded_array=busi_loaded_array)
193
+ out_pu = question_answer(question= typed_ques, openAI_key= openAI_key)
194
+ #print(out_pu)
195
+ return out_pu, type_of_query
196
+
197
 
198
  title = 'CDI Citizen Intelligence 360 Tool: Tax Advisory'
199
  #description = """ Citizen Intelligence 360 sources data from various government agencies and makes it accessible to citizens in a user-friendly format. This can help citizens better understand how their local government works and stay informed about important initiatives and changes in their communities. Citizen Intelligence 360 is a citizen intelligence tool that uses mapping technology to provide citizens with access to government data, performance report and other civic information. It helps to increase transparency and accountability in local government, and empowers citizens to make informed decisions and participate in the democratic process."""
 
210
  history = history or []
211
 
212
  typed_ques = input
213
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  answe, query_type = output_generation(typed_ques)
215
 
216
+ ccc = "{0}".format(answe)
217
+ output = ccc
218
+ history.append((input,output))
219
+ #print(history)
220
+ return history, history
221
 
222
 
223