sergiomar73 commited on
Commit
7a6c0da
β€’
1 Parent(s): 3ae9371

Initial version

Browse files
Files changed (2) hide show
  1. app.py +102 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datetime
2
+ import requests
3
+ import gradio as gr
4
+ import pandas as pd
5
+ from io import BytesIO
6
+ from pathlib import Path
7
+ from urllib.parse import urlparse
8
+ from pydub import AudioSegment, silence
9
+
10
+
11
+ def format_seconds(secs):
12
+ t = datetime.datetime(
13
+ year=1, month=1, day=1, hour=0, minute=0
14
+ ) + datetime.timedelta(seconds=secs)
15
+ return t.strftime("%M:%S.%f")[:-3]
16
+
17
+
18
+ def get_filename_and_extension(url):
19
+ parsed_url = urlparse(url)
20
+ path = parsed_url.path
21
+ filename = Path(path).name
22
+ filename_without_extension = Path(filename).stem
23
+ file_extension = Path(filename).suffix
24
+ return filename, filename_without_extension, file_extension
25
+
26
+
27
+ def calculate_times(input_url, input_text, ms_before, ms_after):
28
+ _, _, file_extension = get_filename_and_extension(input_url)
29
+ file_extension = file_extension.replace(".", "")
30
+ res = requests.get(input_url)
31
+ audio = AudioSegment.from_file(BytesIO(res.content), file_extension)
32
+ non_silent_parts = silence.detect_nonsilent(
33
+ audio, min_silence_len=1250, silence_thresh=-80
34
+ )
35
+ segments = [
36
+ (
37
+ format_seconds((start - ms_before) / 1000),
38
+ format_seconds((stop + ms_after) / 1000),
39
+ )
40
+ for start, stop in non_silent_parts
41
+ ]
42
+ lines = input_text.splitlines()
43
+ if len(lines) != len(segments):
44
+ raise gr.Error("Detected clips and input lines do not match!")
45
+ else:
46
+ df = pd.DataFrame({"text": [], "start": [], "stop": [], "file": []})
47
+ res = []
48
+ for i in range(len(segments)):
49
+ line = lines[i].rstrip()
50
+ res.append(f"{line}\t{segments[i][0]}\t{segments[i][1]}\t{input_url}")
51
+ df.loc[len(df.index)] = [line, segments[i][0], segments[i][1], input_url]
52
+ return input_url, "\n".join(res), df
53
+
54
+
55
+ demo = gr.Interface(
56
+ fn=calculate_times,
57
+ inputs=[
58
+ gr.Textbox(lines=1, placeholder="Video URL...", label="Video URL"),
59
+ gr.Textbox(lines=10, placeholder="Lines...", label="Lines"),
60
+ gr.Slider(
61
+ minimum=0,
62
+ maximum=1000,
63
+ step=50,
64
+ value=0,
65
+ label="Milliseconds BEFORE each clip",
66
+ ),
67
+ gr.Slider(
68
+ minimum=0,
69
+ maximum=1000,
70
+ step=50,
71
+ value=0,
72
+ label="Milliseconds AFTER each clip",
73
+ ),
74
+ ],
75
+ outputs=[
76
+ gr.Video(format="mp4", label="Video file", show_label=True),
77
+ gr.Textbox(lines=10, label="Clips", interactive=False, show_copy_button=True),
78
+ gr.Dataframe(
79
+ label="Clips",
80
+ headers=["text", "start", "stop", "file"],
81
+ datatype=["str", "str", "str", "str"],
82
+ row_count=0,
83
+ # col_count=(4, "fixed"),
84
+ ),
85
+ ],
86
+ examples=[
87
+ [
88
+ "https://simulation-temporary-test.s3.amazonaws.com/SanofiFluCoach.mp4",
89
+ 'Are you ready to jump into a practice? Just say "Lets Practice"\nIf you\'d like to return to the menu, say "Main Menu"\nMain Menu\nPlease say or click one of the choices above\nWelcome back.\nGreat to have you back.\nIt\'s a pleasure to have you back\nWelcome home.\nWould you like to hop on another call? Or do you need to hop off?\nYou can also just return to the main menu.\nDo you have time for another practice?\nLooks like you didn\'t make it all the way through the call.\nYou\'ll need to start over next time, but it will only take a few minutes.\nYou can choose to do it again now, or you can return to the main menu.\nYou hung up on that call in a hurry.\nDo you want to try again now or return to the main menu?\nAre you ready to view your results?\nYour results are ready. Let\'s take a look. Say or click "show my results"\nThe results are in. Say or click "show my results" to take a look.\nReady to see how you did? Say or click "show my results" to check it out.\nYour results are now available. Say or click "show my results"\nWell, I think those were fair questions, and you\'re likely to face those from other HCP\'s as well. So it pays off to be ready. Let\'s see how you did. Click Show my results\nWere you ready for those questions? By exercising your response muscles, you\'ll be even more ready next time questions like these come up.\nDo you want an overview of Simulator? Or, tips on how-to practice?',
90
+ 0,
91
+ 0,
92
+ ],
93
+ [
94
+ "https://simulation-temporary-test.s3.amazonaws.com/SanofiVisAidAvatarPoppy.mp4",
95
+ "Let's get started! You will soon be connected to Dr. Poppy Thompson, an AI physician who is interested in this new drug. Be prepared to discuss all areas of the Beyfortus Visual Aid and to answer any questions she might have. I will give you a few moments to prepare. When you are ready to start the call, just say \"Let's Go\".\nHi, great to see you! I understand you are here to talk to me about your new RSV product. Why don't you jump in? What is it, and what is it for?\nThat's interesting. Why do all infants need protection against RSV?\nUnderstood, so will the protection offered by Beyfortus last for the entire RSV season?\nTell me about the clinical trials – can you give me a broad overview of what was measured?\nThanks, can we dive deeper into Trial 4? What were the results of the primary endpoints, what do I need to take away here?\nI noticed that Beyfortus didn't meet the secondary endpoint of hospitalization in Trial 4. Can you please elaborate on that?\nThanks, let's also take a closer look at Trial three. What were the results of the primary endpoints, what do I need to take-away here?\nThat all sounds great, but is Beyfortus safe? Were there any adverse reactions?\nSo, I know RSV is seasonal, and Beyfortus offers 5 months of protection. How can I fit this into my immunization schedule?\nWhat do I need to know from an administration standpoint?\nThinking through some of the practical considerations, how is Beyfortus administered? How is Beyfortus stored, and what is its shelf-life?\nThanks for your time today – it's definitely very interesting.\nThis has been so helpful. I really appreciate your time today. I do think this makes sense – let's determine next steps to make sure we're protecting all infants from RSV by using Beyfortus. Take care!",
96
+ 0,
97
+ 0,
98
+ ],
99
+ ],
100
+ )
101
+
102
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ pydub
3
+ requests