AbeerTrial commited on
Commit
252c37d
·
1 Parent(s): 3dea2f0

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +98 -35
app.py CHANGED
@@ -1,5 +1,29 @@
1
- import shutil
2
- import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  # def copy_files(source_folder, destination_folder):
5
  # # Create the destination folder if it doesn't exist
@@ -20,10 +44,13 @@ import os
20
 
21
  # # Specify the source folder and destination folder paths
22
  # source_folder = "/kaggle/input/fiver-app5210"
23
- # destination_folder = "/local_db"
24
 
25
  # copy_files(source_folder, destination_folder)
26
 
 
 
 
27
  # def copy_files(source_folder, destination_folder):
28
  # # Create the destination folder if it doesn't exist
29
  # if not os.path.exists(destination_folder):
@@ -43,7 +70,7 @@ import os
43
 
44
  # # Specify the source folder and destination folder paths
45
  # source_folder = "/kaggle/input/fiver-app-docs"
46
- # destination_folder = "/docs"
47
 
48
  # copy_files(source_folder, destination_folder)
49
 
@@ -51,8 +78,8 @@ import os
51
  import openai
52
 
53
  os.environ["TOKENIZERS_PARALLELISM"] = "false"
54
- os.environ["OPENAI_API_KEY"]
55
-
56
 
57
  def api_key(key):
58
 
@@ -190,16 +217,17 @@ def delete_file():
190
  return "Already Deleted"
191
 
192
  import os
 
193
 
194
- def list_files_in_directory(directory):
 
195
  file_list = []
196
  for root, dirs, files in os.walk(directory):
197
  for file in files:
198
  file_list.append(file)
199
- return file_list
200
 
201
- directory_path = '/home/user/app/docs'
202
- file_list = list_files_in_directory(directory_path)
203
 
204
  print("List of file names in the directory:")
205
  for file_name in file_list:
@@ -281,6 +309,26 @@ def audio_text(filepath):
281
 
282
  return output
283
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  def text_soap():
285
  from langchain.llms import OpenAI
286
  from langchain import PromptTemplate, LLMChain
@@ -303,10 +351,13 @@ def text_soap():
303
 
304
  return response
305
 
 
 
306
  def docx(name):
307
  global response
308
  response = response
309
  import docx
 
310
  path = f"/home/user/app/docs/{name}.docx"
311
 
312
  doc = docx.Document()
@@ -331,27 +382,27 @@ css = """
331
  with gr.Blocks(css=css) as demo:
332
  gr.Markdown("File Chatting App")
333
 
334
- with gr.Tab("Chat with your Files"):
335
  with gr.Column(elem_classes="col"):
336
 
337
- with gr.Tab("Upload and Process your Files"):
338
  with gr.Column():
339
 
340
- api_key_input = gr.Textbox(label="Enter your API Key here")
341
  api_key_button = gr.Button("Submit")
342
  api_key_output = gr.Textbox(label="Output")
343
 
344
- file_input = gr.Files(label="Upload your File(s) here")
345
  upload_button = gr.Button("Upload")
346
  file_output = gr.Textbox(label="Output")
347
 
348
  process_button = gr.Button("Process")
349
  process_output = gr.Textbox(label="Output")
350
 
351
- with gr.Tab("Ask Questions to your Files"):
352
  with gr.Column():
353
 
354
- search_input = gr.Textbox(label="Enter your Question here")
355
  search_button = gr.Button("Search")
356
  search_output = gr.Textbox(label="Output")
357
 
@@ -361,10 +412,10 @@ with gr.Blocks(css=css) as demo:
361
  delete_button = gr.Button("Delete")
362
  delete_output = gr.Textbox(label="Output")
363
 
364
- with gr.Tab("Chat with your Local Files"):
365
  with gr.Column(elem_classes="col"):
366
 
367
- local_search_input = gr.Textbox(label="Enter your Question here")
368
  local_search_button = gr.Button("Search")
369
  local_search_output = gr.Textbox(label="Output")
370
 
@@ -374,28 +425,39 @@ with gr.Blocks(css=css) as demo:
374
  with gr.Tab("Ask Question to SOAP Report"):
375
  with gr.Column(elem_classes="col"):
376
 
377
- soap_input = gr.Dropdown(choices=file_list, label="Choose File")
378
- soap_question = gr.Textbox(label="Enter your Question here")
 
379
  soap_button = gr.Button("Submit")
380
  soap_output = gr.Textbox(label="Output")
381
 
382
  with gr.Tab("Convert Audio to SOAP Report"):
383
  with gr.Column(elem_classes="col"):
384
 
385
- audio_text_input = gr.Audio(source="microphone", type="filepath", label="Upload your Audio File here")
386
- audio_text_button = gr.Button("Generate Transcript")
387
- audio_text_output = gr.Textbox(label="Output")
 
 
 
 
 
 
 
 
388
 
389
  text_soap_button = gr.Button("Generate SOAP Report")
390
  text_soap_output = gr.Textbox(label="Output")
391
 
392
- docx_input = gr.Textbox(label="Enter the Name of .docx File")
393
  docx_button = gr.Button("Save .docx File")
394
  docx_output = gr.Textbox(label="Output")
395
 
 
396
  api_key_button.click(api_key, inputs=api_key_input, outputs=api_key_output)
397
 
398
  upload_button.click(save_file, inputs=file_input, outputs=file_output)
 
399
  process_button.click(process_file, inputs=None, outputs=process_output)
400
 
401
  search_button.click(search_file, inputs=search_input, outputs=search_output)
@@ -406,27 +468,28 @@ with gr.Blocks(css=css) as demo:
406
  local_search_button.click(search_local, inputs=local_search_input, outputs=local_search_output)
407
  local_gpt_button.click(local_gpt, inputs=local_search_input, outputs=local_gpt_output)
408
 
 
409
  soap_button.click(soap_report, inputs=[soap_input, soap_question], outputs=soap_output)
410
 
411
- audio_text_button.click(audio_text, inputs=audio_text_input, outputs=audio_text_output)
412
- text_soap_button.click(text_soap, inputs=None, outputs=text_soap_output)
413
 
414
- audio_text_button.click(audio_text, inputs=audio_text_input, outputs=audio_text_output)
415
  text_soap_button.click(text_soap, inputs=None, outputs=text_soap_output)
416
  docx_button.click(docx, inputs=docx_input, outputs=docx_output)
417
 
418
 
419
  demo.queue()
420
- demo.launch()
421
-
422
 
 
423
 
424
- # # Commented out IPython magic to ensure Python compatibility.
425
- # #download file_db
426
 
427
- # # %cd /kaggle/working/
428
 
429
- # !zip -r "file_db.zip" "file_db"
430
 
431
- # from IPython.display import FileLink
432
- # FileLink("file_db.zip")
 
1
+ # # -*- coding: utf-8 -*-
2
+ # """fiver-app.ipynb
3
+
4
+ # Automatically generated by Colaboratory.
5
+
6
+ # Original file is located at
7
+ # https://colab.research.google.com/drive/1YQm_fGxa2nfiV8pTN4oBrlzzfefGadaP
8
+ # """
9
+
10
+ # !pip uninstall -y numpy
11
+ # !pip install --ignore-installed numpy==1.22.0
12
+
13
+ # !pip install langchain
14
+ # !pip install PyPDF2
15
+ # !pip install docx2txt
16
+ # !pip install gradio
17
+ # !pip install faiss-gpu
18
+ # !pip install openai
19
+ # !pip install tiktoken
20
+ # !pip install python-docx
21
+
22
+ # !pip install git+https://github.com/openai/whisper.git
23
+ # !pip install sounddevice
24
+
25
+ # import shutil
26
+ # import os
27
 
28
  # def copy_files(source_folder, destination_folder):
29
  # # Create the destination folder if it doesn't exist
 
44
 
45
  # # Specify the source folder and destination folder paths
46
  # source_folder = "/kaggle/input/fiver-app5210"
47
+ # destination_folder = "/home/user/app/local_db"
48
 
49
  # copy_files(source_folder, destination_folder)
50
 
51
+ # import shutil
52
+ # import os
53
+
54
  # def copy_files(source_folder, destination_folder):
55
  # # Create the destination folder if it doesn't exist
56
  # if not os.path.exists(destination_folder):
 
70
 
71
  # # Specify the source folder and destination folder paths
72
  # source_folder = "/kaggle/input/fiver-app-docs"
73
+ # destination_folder = "/home/user/app/docs"
74
 
75
  # copy_files(source_folder, destination_folder)
76
 
 
78
  import openai
79
 
80
  os.environ["TOKENIZERS_PARALLELISM"] = "false"
81
+ os.environ["OPENAI_API_KEY"] = "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"
82
+ openai.api_key = "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"
83
 
84
  def api_key(key):
85
 
 
217
  return "Already Deleted"
218
 
219
  import os
220
+ import gradio as gr
221
 
222
+ def list_files():
223
+ directory = '/home/user/app/docs'
224
  file_list = []
225
  for root, dirs, files in os.walk(directory):
226
  for file in files:
227
  file_list.append(file)
228
+ return gr.Dropdown.update(choices=file_list)
229
 
230
+ file_list = list_files()
 
231
 
232
  print("List of file names in the directory:")
233
  for file_name in file_list:
 
309
 
310
  return output
311
 
312
+ def transcript(text):
313
+ from langchain.llms import OpenAI
314
+ from langchain import PromptTemplate, LLMChain
315
+ global response
316
+
317
+ question = "Use the following context given below to generate a detailed SOAP Report:\n\n"
318
+ question += text
319
+ print(question)
320
+
321
+ template = """Question: {question}
322
+
323
+ Answer: Let's think step by step."""
324
+
325
+ prompt = PromptTemplate(template=template, input_variables=["question"])
326
+ llm = OpenAI()
327
+ llm_chain = LLMChain(prompt=prompt, llm=llm)
328
+ response = llm_chain.run(question)
329
+
330
+ return response
331
+
332
  def text_soap():
333
  from langchain.llms import OpenAI
334
  from langchain import PromptTemplate, LLMChain
 
351
 
352
  return response
353
 
354
+ global path
355
+
356
  def docx(name):
357
  global response
358
  response = response
359
  import docx
360
+ global path
361
  path = f"/home/user/app/docs/{name}.docx"
362
 
363
  doc = docx.Document()
 
382
  with gr.Blocks(css=css) as demo:
383
  gr.Markdown("File Chatting App")
384
 
385
+ with gr.Tab("Chat with Files"):
386
  with gr.Column(elem_classes="col"):
387
 
388
+ with gr.Tab("Upload and Process Files"):
389
  with gr.Column():
390
 
391
+ api_key_input = gr.Textbox(label="Enter PI Key here")
392
  api_key_button = gr.Button("Submit")
393
  api_key_output = gr.Textbox(label="Output")
394
 
395
+ file_input = gr.Files(label="Upload File(s) here")
396
  upload_button = gr.Button("Upload")
397
  file_output = gr.Textbox(label="Output")
398
 
399
  process_button = gr.Button("Process")
400
  process_output = gr.Textbox(label="Output")
401
 
402
+ with gr.Tab("Ask Questions to Files"):
403
  with gr.Column():
404
 
405
+ search_input = gr.Textbox(label="Enter Question here")
406
  search_button = gr.Button("Search")
407
  search_output = gr.Textbox(label="Output")
408
 
 
412
  delete_button = gr.Button("Delete")
413
  delete_output = gr.Textbox(label="Output")
414
 
415
+ with gr.Tab("Chat with Local Files"):
416
  with gr.Column(elem_classes="col"):
417
 
418
+ local_search_input = gr.Textbox(label="Enter Question here")
419
  local_search_button = gr.Button("Search")
420
  local_search_output = gr.Textbox(label="Output")
421
 
 
425
  with gr.Tab("Ask Question to SOAP Report"):
426
  with gr.Column(elem_classes="col"):
427
 
428
+ refresh_button = gr.Button("Refresh")
429
+ soap_input = gr.Dropdown(label="Choose File")
430
+ soap_question = gr.Textbox(label="Enter Question here")
431
  soap_button = gr.Button("Submit")
432
  soap_output = gr.Textbox(label="Output")
433
 
434
  with gr.Tab("Convert Audio to SOAP Report"):
435
  with gr.Column(elem_classes="col"):
436
 
437
+ mic_text_input = gr.Audio(source="microphone", type="filepath", label="Speak to the Microphone")
438
+ mic_text_button = gr.Button("Generate Transcript")
439
+ mic_text_output = gr.Textbox(label="Output")
440
+
441
+ upload_text_input = gr.Audio(source="upload", type="filepath", label="Upload Audio File here")
442
+ upload_text_button = gr.Button("Generate Transcript")
443
+ upload_text_output = gr.Textbox(label="Output")
444
+
445
+ transcript_input = gr.Textbox(label="Enter Transcript here")
446
+ transcript_button = gr.Button("Generate SOAP Report")
447
+ transcript_output = gr.Textbox(label="Output")
448
 
449
  text_soap_button = gr.Button("Generate SOAP Report")
450
  text_soap_output = gr.Textbox(label="Output")
451
 
452
+ docx_input = gr.Textbox(label="Enter the name of .docx File")
453
  docx_button = gr.Button("Save .docx File")
454
  docx_output = gr.Textbox(label="Output")
455
 
456
+
457
  api_key_button.click(api_key, inputs=api_key_input, outputs=api_key_output)
458
 
459
  upload_button.click(save_file, inputs=file_input, outputs=file_output)
460
+
461
  process_button.click(process_file, inputs=None, outputs=process_output)
462
 
463
  search_button.click(search_file, inputs=search_input, outputs=search_output)
 
468
  local_search_button.click(search_local, inputs=local_search_input, outputs=local_search_output)
469
  local_gpt_button.click(local_gpt, inputs=local_search_input, outputs=local_gpt_output)
470
 
471
+ refresh_button.click(list_files, inputs=None, outputs=soap_input)
472
  soap_button.click(soap_report, inputs=[soap_input, soap_question], outputs=soap_output)
473
 
474
+ mic_text_button.click(audio_text, inputs=mic_text_input, outputs=mic_text_output)
475
+ upload_text_button.click(audio_text, inputs=upload_text_input, outputs=upload_text_output)
476
 
477
+ transcript_button.click(transcript, inputs=transcript_input, outputs=transcript_output)
478
  text_soap_button.click(text_soap, inputs=None, outputs=text_soap_output)
479
  docx_button.click(docx, inputs=docx_input, outputs=docx_output)
480
 
481
 
482
  demo.queue()
483
+ demo.launch(debug=True, share=True)
 
484
 
485
+ ls /home/user/app/docs/
486
 
487
+ # Commented out IPython magic to ensure Python compatibility.
488
+ #download file_db
489
 
490
+ # %cd /home/user/app/
491
 
492
+ !zip -r "file_db.zip" "file_db"
493
 
494
+ from IPython.display import FileLink
495
+ FileLink("file_db.zip")