Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,7 @@ import pandas as pd
|
|
10 |
from datetime import datetime, timezone, timedelta
|
11 |
import notion_df
|
12 |
import concurrent.futures
|
|
|
13 |
|
14 |
# Define the tokenizer and model
|
15 |
tokenizer = GPT2Tokenizer.from_pretrained('gpt2-medium')
|
@@ -126,8 +127,12 @@ def transcribe(audio, text):
|
|
126 |
df = pd.DataFrame([chat_transcript])
|
127 |
notion_df.upload(df, 'https://www.notion.so/YENA-be569d0a40c940e7b6e0679318215790?pvs=4', title=str(published_date), api_key=API_KEY)
|
128 |
|
129 |
-
#
|
130 |
-
|
|
|
|
|
|
|
|
|
131 |
|
132 |
# Define the input and output components for Gradio
|
133 |
audio_input = Audio(source="microphone", type="filepath", label="Record your message")
|
@@ -135,11 +140,29 @@ text_input = Textbox(label="Type your message", max_length=4096)
|
|
135 |
output_text = gr.outputs.Textbox(label="Response")
|
136 |
output_audio = Audio()
|
137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
# Define the Gradio interface
|
139 |
iface = gr.Interface(
|
140 |
fn=transcribe,
|
141 |
inputs=[audio_input, text_input],
|
142 |
outputs=[output_text],
|
|
|
143 |
title="Hold On, Pain Ends (HOPE)",
|
144 |
description="Talk to Your USMLE Tutor HOPE",
|
145 |
theme="compact",
|
|
|
10 |
from datetime import datetime, timezone, timedelta
|
11 |
import notion_df
|
12 |
import concurrent.futures
|
13 |
+
from IPython.core.display import HTML
|
14 |
|
15 |
# Define the tokenizer and model
|
16 |
tokenizer = GPT2Tokenizer.from_pretrained('gpt2-medium')
|
|
|
127 |
df = pd.DataFrame([chat_transcript])
|
128 |
notion_df.upload(df, 'https://www.notion.so/YENA-be569d0a40c940e7b6e0679318215790?pvs=4', title=str(published_date), api_key=API_KEY)
|
129 |
|
130 |
+
# Colorize the system message text
|
131 |
+
colorized_system_message = colorize_text(system_message['content'])
|
132 |
+
|
133 |
+
# Return the colorized chat transcript
|
134 |
+
return colorized_system_message
|
135 |
+
|
136 |
|
137 |
# Define the input and output components for Gradio
|
138 |
audio_input = Audio(source="microphone", type="filepath", label="Record your message")
|
|
|
140 |
output_text = gr.outputs.Textbox(label="Response")
|
141 |
output_audio = Audio()
|
142 |
|
143 |
+
|
144 |
+
def colorize_text(text):
|
145 |
+
doc = nlp(text)
|
146 |
+
colorized_text = ""
|
147 |
+
|
148 |
+
for token in doc:
|
149 |
+
if token.ent_type_:
|
150 |
+
colorized_text += f'<span style="background-color: yellow;">{token.text_with_ws}</span>'
|
151 |
+
elif token.pos_ in {'NOUN'}:
|
152 |
+
colorized_text += f'<span style="color: blue;">{token.text_with_ws}</span>'
|
153 |
+
else:
|
154 |
+
colorized_text += token.text_with_ws
|
155 |
+
|
156 |
+
return colorized_text
|
157 |
+
|
158 |
+
|
159 |
+
|
160 |
# Define the Gradio interface
|
161 |
iface = gr.Interface(
|
162 |
fn=transcribe,
|
163 |
inputs=[audio_input, text_input],
|
164 |
outputs=[output_text],
|
165 |
+
output_text = gr.outputs.HTML(label="Response"),
|
166 |
title="Hold On, Pain Ends (HOPE)",
|
167 |
description="Talk to Your USMLE Tutor HOPE",
|
168 |
theme="compact",
|