Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,78 +1,37 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
"Sarah does not take any medications regularly.\n\n"
|
39 |
-
"Her last dental visit was about a year ago, so this is her second visit. "
|
40 |
-
"Sarah has a habit of occasionally biting her nails, but she doesn't have any other habits like thumb sucking or tongue thrusting.\n\n"
|
41 |
-
"Sarah brushes her teeth twice daily. She does not experience bleeding gums. "
|
42 |
-
"Sarah has not experienced early childhood caries. Unfortunately, she does have tooth decay present in tooth numbers 14 and 15. "
|
43 |
-
"None of her teeth have been fractured. There is no pre-shedding mobility of teeth to report.\n\n"
|
44 |
-
"Sarah does not have malocclusion. She does not experience any pain, swelling, or abscess at the moment. "
|
45 |
-
"There are no other significant findings to note.\n\n"
|
46 |
-
"As for the treatment plan, I would recommend a filling for the decayed teeth."
|
47 |
-
)
|
48 |
-
|
49 |
-
# Load the GPT-2 model for text generation
|
50 |
-
generator = pipeline('text-generation', model='gpt2')
|
51 |
-
|
52 |
-
# Function to generate answers
|
53 |
-
def generate_answers(context):
|
54 |
-
prompt = context + "\n\n" + "\n\n".join(questions)
|
55 |
-
set_seed(42) # Ensure reproducibility
|
56 |
-
generated_text = generator(prompt, max_length=300, num_return_sequences=1)[0]['generated_text']
|
57 |
-
generated_answers = generated_text.split("\n\n")
|
58 |
-
return generated_answers
|
59 |
-
|
60 |
-
# Function to display the form
|
61 |
-
def form_display():
|
62 |
-
return gr.Interface(
|
63 |
-
fn=form_submit,
|
64 |
-
inputs=gr.inputs.Textbox(lines=20, label="Context", default=default_context),
|
65 |
-
outputs=gr.outputs.Textbox(label="Generated Answers", type="text"),
|
66 |
-
title="Dental Health Record Form with GPT-2",
|
67 |
-
description="Fill out the context and click submit to generate answers to the questions.",
|
68 |
-
examples=[default_context],
|
69 |
-
allow_flagging=False
|
70 |
-
)
|
71 |
-
|
72 |
-
# Function to submit the form
|
73 |
-
def form_submit(context):
|
74 |
-
generated_answers = generate_answers(context)
|
75 |
-
return generated_answers
|
76 |
-
|
77 |
-
# Launch the interface
|
78 |
-
form_display().launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import assemblyai as aai
|
3 |
+
import os
|
4 |
+
|
5 |
+
# Replace with your AssemblyAI API key
|
6 |
+
aai.settings.api_key = "62acec891bb04c339ec059b738bedac6"
|
7 |
+
|
8 |
+
# Function to handle audio recording and transcription
|
9 |
+
def transcribe_audio(audio):
|
10 |
+
# Save the recorded audio to a file
|
11 |
+
audio_path = "recorded_audio.wav"
|
12 |
+
audio.save(audio_path)
|
13 |
+
|
14 |
+
# Transcribe the audio file using AssemblyAI
|
15 |
+
transcriber = aai.Transcriber()
|
16 |
+
transcript = transcriber.transcribe(audio_path)
|
17 |
+
|
18 |
+
# Handle the transcription result
|
19 |
+
if transcript.status == aai.TranscriptStatus.error:
|
20 |
+
return transcript.error
|
21 |
+
else:
|
22 |
+
return transcript.text
|
23 |
+
|
24 |
+
# Create the Gradio interface
|
25 |
+
with gr.Blocks() as demo:
|
26 |
+
gr.Markdown("# Audio Transcription App")
|
27 |
+
with gr.Row():
|
28 |
+
with gr.Column():
|
29 |
+
audio_input = gr.Audio(source="microphone", type="file", label="Record your audio")
|
30 |
+
output_text = gr.Textbox(label="Transcription")
|
31 |
+
with gr.Column():
|
32 |
+
transcribe_button = gr.Button("Transcribe")
|
33 |
+
|
34 |
+
transcribe_button.click(fn=transcribe_audio, inputs=audio_input, outputs=output_text)
|
35 |
+
|
36 |
+
# Launch the app
|
37 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|