mmccanse commited on
Commit
b23896e
·
1 Parent(s): 5e42034

create backup file

Browse files
Files changed (1) hide show
  1. app_backup_copy.py +124 -0
app_backup_copy.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # In[1]:
5
+
6
+
7
+ # pip install langdetect
8
+ # pip install sentencepiece
9
+ # pip install boto3
10
+ # pip install awscli
11
+ # pip install sacremoses
12
+
13
+
14
+ # In[2]:
15
+
16
+
17
+ import gradio as gr
18
+ from transformers import pipeline, AutoTokenizer, TFAutoModelForSeq2SeqLM
19
+ from dotenv import load_dotenv
20
+ import os
21
+ import subprocess
22
+ import torch
23
+ import tempfile
24
+ from langdetect import detect
25
+ from transformers import MarianMTModel, MarianTokenizer
26
+ import re
27
+ import boto3
28
+
29
+
30
+
31
+ # In[3]:
32
+
33
+
34
+ # import functions from functions file
35
+
36
+ from functions_mm import handle_query, transcribe_audio_original, submit_question, polly_text_to_speech, translate, translate_and_speech, clear_inputs, voice_map, language_map, default_language, languages
37
+
38
+
39
+
40
+ # In[4]:
41
+
42
+
43
+ # Load environment variables.
44
+ load_dotenv()
45
+
46
+ # Set the model name for our LLMs.
47
+ OPENAI_MODEL = "gpt-3.5-turbo"
48
+ # Store the API key in a variable.
49
+ OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
50
+
51
+
52
+ # In[5]:
53
+
54
+
55
+ instructions = """
56
+ # Diabetes Chatbot
57
+ #### Step 1: Record your audio OR input text (NOT both!) -- Step 2: Would you like response in new language? Choose your language
58
+ #### Step 3: Submit question -- Step 4: Translate response -- Step 5: Clear inputs and start fresh
59
+ """
60
+
61
+
62
+ with gr.Blocks() as app2:
63
+
64
+ with gr.Row():
65
+ gr.Markdown(instructions)
66
+
67
+ with gr.Row():
68
+ input_audio = gr.Audio(
69
+ label="Ask a question about Diabetes, then click 'Transcribe audio",
70
+ type="filepath")
71
+ language_dropdown = gr.Dropdown(label="Click the middle of the dropdown bar to select translation language",
72
+ choices=list(language_map.keys()), value=default_language, type='value')
73
+
74
+ with gr.Row():
75
+ transcribe_button = gr.Button("Transcribe audio")
76
+ submit_button = gr.Button("Submit your question")
77
+ translate_button = gr.Button("Translate the response")
78
+ clear_button = gr.Button("Clear All")
79
+
80
+ #Divide the screen horizontally into 2 columns
81
+ with gr.Row():
82
+ #This column will be on the left side of screen
83
+ with gr.Column():
84
+ query_text = gr.Textbox(label="Type your question here. If there is audio recorded AND question text, app will submit question text. Click transcribe button to populate with audio text")
85
+ # output_original_speech = gr.Audio(label="Text to speech here")
86
+
87
+ with gr.Column():
88
+ response_text = gr.Textbox(label="Chatbot response")
89
+ response_speech = gr.Audio(label="Chatbot response speech")
90
+
91
+ #This column will be on the right side of screen
92
+ with gr.Column():
93
+ output_translated = gr.Textbox(label="Translated text")
94
+ output_translated_speech = gr.Audio(label="Translated speech")
95
+
96
+ # Audio transcription
97
+ transcribe_button.click(
98
+ fn=transcribe_audio_original,
99
+ inputs=[input_audio],
100
+ outputs=[query_text]
101
+ )
102
+
103
+ submit_button.click(
104
+ fn=submit_question,
105
+ inputs=[input_audio, query_text, language_dropdown],
106
+ outputs=[response_text, response_speech]
107
+ )
108
+
109
+ # Translation
110
+ translate_button.click(
111
+ fn=translate_and_speech,
112
+ inputs=[response_text, language_dropdown],
113
+ outputs=[output_translated, output_translated_speech]
114
+ )
115
+
116
+ #Clearing all inputs and outputs
117
+ clear_button.click(
118
+ fn=clear_inputs,
119
+ inputs=[],
120
+ outputs=[input_audio, query_text, response_text, response_speech, output_translated, output_translated_speech]
121
+ )
122
+
123
+ app2.launch(show_error=True)
124
+