Unggi commited on
Commit
2b60f7b
1 Parent(s): 0789093

page 1 and page 2 were seperated

Browse files
Files changed (3) hide show
  1. vocal_app.py +168 -121
  2. vocal_app.sh +1 -0
  3. vocal_app2.py +0 -165
vocal_app.py CHANGED
@@ -1,139 +1,186 @@
1
- import whisper
2
- import gradio as gr
3
- from dotenv import dotenv_values
4
- import openai
5
- import os
6
 
7
- """
8
- apt-get update
9
- apt-get install ffmpeg
10
- """
11
 
12
- config = dotenv_values(".env")
 
13
 
14
- openai.organization = config.get('OPENAI_ORGANIZATION')
15
- openai.api_key = config.get('OPENAI_API_KEY')
16
 
 
 
17
 
18
- def transcribe(audio):
19
- os.rename(audio, audio + '.wav')
20
- file = open(audio + '.wav', "rb")
21
 
22
- result = openai.Audio.transcribe("whisper-1", file).text
23
 
24
- return result
 
 
 
 
 
25
 
26
- with gr.Blocks() as app:
27
- # 주제선택
28
- with gr.Tab("Selecting Subject"):
29
- debate_theme = gr.Dropdown(
30
- ['Education','Sports','Religion','Justice','Pandemic','Politics','Minority','etc'],
31
- label="Debate Theme",
32
- info="Select a theme for the debate."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  )
34
- submit_button = gr.Button("Submit")
35
-
36
-
37
- if debate_theme.value == "Education":
38
- topic_list = [
39
- "THBT college entrance examinations should accept students only on the basis of their academic performance in secondary education.",
40
- "THS a world where the government gives cash that individuals can use to freely select their academic preference (including but not limited to school of choice, private academies, and tutoring) instead of funding for public education.",
41
- "THW abolish all requirements and evaluation criteria in higher education (i.e., attendance, exams, assignments)."
42
  ]
43
- elif debate_theme.value == "Sports":
44
- topic_list = [
45
- "THBT having star players for team sports do more harm than good to the team.",
46
- "THR the emphasis on winning a medal in the Olympics as a core symbol of success.",
47
- "THP a world where sports serves purely entertainment purposes even at the expense of fair play."
 
48
  ]
49
- elif debate_theme.value == "Religion":
50
- topic_list = [
51
- "THW, as a religious group/leader, cease attempts at increasing the number of believers and instead prioritize boosting loyalty amongst adherents to the religion.",
52
- "Assuming feasibility, TH prefers a world where a panel of church leaders would create a universally accepted interpretation of the Bible that the believers would abide by.",
53
- "THW aggressively crackdown on megachurches."
 
54
  ]
55
- elif debate_theme.value == "Justice":
56
- topic_list = [
57
- "In 2050, AI robots are able to replicate the appearance, conversation, and reaction to emotions of human beings. However, their intelligence still does not allow them to sense emotions and feelings such as pain, happiness, joy, and etc.",
58
- "In the case a human destroys the robot beyond repair, THW charge murder instead of property damage.",
59
- "THP a world where the criminal justice system’s role is mainly for victim’s vengeance. THW allow prosecutors and victims to veto assigned judges."
 
60
  ]
61
- elif debate_theme.value == "Pandemic":
62
- topic_list = [
63
- "During a pandemic, THBT businesses that benefit from the pandemic should be additionally taxed.",
64
- "THW nullify the effect of medical patents in cases of medical emergencies.",
65
- "THW ban media content that denies the efficacy of the COVID-19 without substantial evidence."
 
66
  ]
67
- elif debate_theme.value == "Politics":
68
- topic_list = [
69
- "Info: The Candle Light Will (촛불민심) is a term derived from the symbolic candle-light protests for the impeachment of the late president Park Geun Hye, commonly used to mean the people’s will to fight against corrupt governments. The Moon administration has frequently referred to the Candle Light Will as the driving force behind its election that grants legitimacy to its policies. THR the ‘candle light will’ narrative in the political discourse of South Korea.",
70
- "THW impose a cap on the property and income of politicians.",
71
- "THW give the youth extra votes."
 
72
  ]
73
- elif debate_theme.value == "Minority":
74
- topic_list = [
75
- "Context: A prominent member of the LGBT movement has discovered that a very influential politician helping the LGBT movement has been lying about their sexual orientation as being gay when they are straight. THW disclose this information.",
76
- "THBT the LGBTQIA+ movement should denounce the existence of marriage as opposed to fighting for equal marriage rights.",
77
- "THBT the LGBTQIA+ movement should condemn the consumption of movies and TV shows that cast straight actors/actresses in non-heterosexual identified roles."
 
78
  ]
79
- else:
80
- topic_list = [
81
- "THW remove all laws that relate to filial responsibilities.",
82
- "THW require parents to receive approval from experts in relevant fields before making crucial decisions for their children.",
83
- "Assuming it is possible to measure the ‘societal danger’ of the fetus in the future, THBT the state should raise infants that pose high levels of threat.",
84
- "THBT any upper limits on prison sentences for particularly heinous crimes should be abolished.",
85
- "THW require dating apps to anonymize profile pictures.",
86
- "THW adopt a Pass/Fail grading system for students who suffer from mental health problems (e.g. depression, bipolar disorder, etc.).",
87
- "THBT South Korean feminist movements should reject feminist icons that are adversarial and embody violence.",
88
- "THBT freedom of speech should be considered obsolete.",
89
- "THR the narrative that eccentric personalities are essential to create art.",
90
- "THW allow parents of severely mentally disabled children to medically impede their children's physical growth.",
91
- "THR the emphasis on longevity in relationships.",
92
- "Assuming feasibility, THW choose to continuously relive the happiest moment of one’s life."
 
93
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
- debate_topic = gr.Dropdown(
96
- topic_list,
97
- label="Debate Topic",
98
- info="Select a topic for the debate."
99
- )
100
- text_input = gr.Textbox()
101
- text_output = gr.Textbox()
102
- text_button = gr.Button("Flip")
103
-
104
- # 토론준비
105
- with gr.Tab("Ready to Debate"):
106
- text_input = gr.Textbox()
107
- text_output = gr.Textbox()
108
- text_button = gr.Button("Flip")
109
-
110
- # 토론연습
111
- with gr.Tab("Practice Debate"):
112
- text_input = gr.Textbox()
113
- text_output = gr.Textbox()
114
- text_button = gr.Button("Flip")
115
-
116
- # 토론평가
117
- with gr.Tab("Evaluate Debate"):
118
- text_input = gr.Textbox()
119
- text_output = gr.Textbox()
120
- text_button = gr.Button("Flip")
121
-
122
- # 발화분석
123
- with gr.Tab("Analysis Voice"):
124
- text_input = gr.Textbox()
125
- text_output = gr.Textbox()
126
- text_button = gr.Button("Flip")
127
-
128
-
129
- app.launch()
130
- #submit = gr.inputs.Button(label="Submit")
131
- # gr.Interface(
132
- # title = 'Whisper Audio to Text with Speaker Recognition',
133
- # fn=transcribe,
134
- # inputs=[
135
- # gr.inputs.Audio(source="microphone", type="filepath"),
136
- # #gr.inputs.Number(default=2, label="Number of Speakers")
137
- # ],
138
- # outputs="text"
139
- # ).launch()
 
1
+ import streamlit as st
2
+ #import SessionState
 
 
 
3
 
4
+ # Page Configuration
5
+ st.set_page_config(page_title="Streamlit App")
 
 
6
 
7
+ if "page" not in st.session_state:
8
+ st.session_state.page = "Page 1"
9
 
10
+ if "topic" not in st.session_state:
11
+ st.session_state.topic = "None"
12
 
13
+ if "user_id" not in st.session_state:
14
+ st.session_state.user_id = ""
15
 
16
+ if "openAI_token" not in st.session_state:
17
+ st.session_state.openAI_token = ""
 
18
 
 
19
 
20
+ # Save function (placeholder)
21
+ def save_info(user_id, openAI_token, debate_theme):
22
+ # You can add the code to save the submitted info (e.g., to a database)
23
+ st.session_state.user_id = user_id
24
+ st.session_state.openAI_token = openAI_token
25
+ st.session_state.debate_theme = debate_theme
26
 
27
+ print("User ID:", user_id)
28
+ print("OpenAI token:", openAI_token)
29
+ print("Debate theme:", debate_theme)
30
+
31
+ # Session state
32
+ #session_state = SessionState.get(user_id="", openAI_token="", debate_theme="")
33
+
34
+ def write_info():
35
+ st.write('You choose', st.session_state.topic_list)
36
+
37
+ # for callback when button is clicked
38
+ def page_controller():
39
+ if st.session_state.user_id.strip() == "" or st.session_state.openAI_token.strip() == "":
40
+ st.session_state.page = "Page 1"
41
+ st.warning('Please fill in all the required fields.')
42
+ else:
43
+ st.session_state.page = "Page 2"
44
+
45
+
46
+ # Page 1
47
+ def page1():
48
+
49
+ # for local variables
50
+ topic_list = []
51
+
52
+ st.header('User Info & Debate Setting')
53
+ st.session_state.user_id = st.text_input(
54
+ label="Enter user ID",
55
+ max_chars=100,
56
+ placeholder="Enter user ID"
57
+ )
58
+ st.session_state.openAI_token = st.text_input(
59
+ label="Enter OpenAI token",
60
+ max_chars=200,
61
+ placeholder="Enter OpenAI token"
62
  )
63
+ debate_themes = ['Education','Sports','Religion','Justice','Pandemic','Politics','Minority','etc']
64
+ st.session_state.debate_theme = st.selectbox("Select a debate theme", debate_themes)
65
+
66
+ if st.session_state.debate_theme == 'Education':
67
+ topic_list = [
68
+ "THBT college entrance examinations should accept students only on the basis of their academic performance in secondary education.",
69
+ "THS a world where the government gives cash that individuals can use to freely select their academic preference (including but not limited to school of choice, private academies, and tutoring) instead of funding for public education.",
70
+ "THW abolish all requirements and evaluation criteria in higher education (i.e., attendance, exams, assignments)."
71
  ]
72
+ #topic = st.selectbox("Select a topic_list", topic_list)
73
+ elif st.session_state.debate_theme == 'Sports':
74
+ topic_list = [
75
+ "THBT having star players for team sports do more harm than good to the team.",
76
+ "THR the emphasis on winning a medal in the Olympics as a core symbol of success.",
77
+ "THP a world where sports serves purely entertainment purposes even at the expense of fair play."
78
  ]
79
+ #topic = st.selectbox("Select a topic_list", topic_list)
80
+ elif st.session_state.debate_theme == 'Religion':
81
+ topic_list = [
82
+ "THW, as a religious group/leader, cease attempts at increasing the number of believers and instead prioritize boosting loyalty amongst adherents to the religion.",
83
+ "Assuming feasibility, TH prefers a world where a panel of church leaders would create a universally accepted interpretation of the Bible that the believers would abide by.",
84
+ "THW aggressively crackdown on megachurches."
85
  ]
86
+ #topic = st.selectbox("Select a topic_list", topic_list)
87
+ elif st.session_state.debate_theme == 'Justice':
88
+ topic_list = [
89
+ "In 2050, AI robots are able to replicate the appearance, conversation, and reaction to emotions of human beings. However, their intelligence still does not allow them to sense emotions and feelings such as pain, happiness, joy, and etc.",
90
+ "In the case a human destroys the robot beyond repair, THW charge murder instead of property damage.",
91
+ "THP a world where the criminal justice system’s role is mainly for victim’s vengeance. THW allow prosecutors and victims to veto assigned judges."
92
  ]
93
+ #topic = st.selectbox("Select a topic_list", topic_list)
94
+ elif st.session_state.debate_theme == 'Pandemic':
95
+ topic_list = [
96
+ "During a pandemic, THBT businesses that benefit from the pandemic should be additionally taxed.",
97
+ "THW nullify the effect of medical patents in cases of medical emergencies.",
98
+ "THW ban media content that denies the efficacy of the COVID-19 without substantial evidence."
99
  ]
100
+ #topic = st.selectbox("Select a topic_list", topic_list)
101
+ elif st.session_state.debate_theme == 'Politics':
102
+ topic_list = [
103
+ "Info: The Candle Light Will (촛불민심) is a term derived from the symbolic candle-light protests for the impeachment of the late president Park Geun Hye, commonly used to mean the people’s will to fight against corrupt governments. The Moon administration has frequently referred to the Candle Light Will as the driving force behind its election that grants legitimacy to its policies. THR the ‘candle light will’ narrative in the political discourse of South Korea.",
104
+ "THW impose a cap on the property and income of politicians.",
105
+ "THW give the youth extra votes."
106
  ]
107
+ #topic = st.selectbox("Select a topic_list", topic_list)
108
+ elif st.session_state.debate_theme == 'Minority':
109
+ topic_list = [
110
+ "Context: A prominent member of the LGBT movement has discovered that a very influential politician helping the LGBT movement has been lying about their sexual orientation as being gay when they are straight. THW disclose this information.",
111
+ "THBT the LGBTQIA+ movement should denounce the existence of marriage as opposed to fighting for equal marriage rights.",
112
+ "THBT the LGBTQIA+ movement should condemn the consumption of movies and TV shows that cast straight actors/actresses in non-heterosexual identified roles."
113
  ]
114
+ #topic = st.selectbox("Select a topic_list", topic_list)
115
+ else:
116
+ topic_list = [
117
+ "THW remove all laws that relate to filial responsibilities.",
118
+ "THW require parents to receive approval from experts in relevant fields before making crucial decisions for their children.",
119
+ "Assuming it is possible to measure the ‘societal danger’ of the fetus in the future, THBT the state should raise infants that pose high levels of threat.",
120
+ "THBT any upper limits on prison sentences for particularly heinous crimes should be abolished.",
121
+ "THW require dating apps to anonymize profile pictures.",
122
+ "THW adopt a Pass/Fail grading system for students who suffer from mental health problems (e.g. depression, bipolar disorder, etc.).",
123
+ "THBT South Korean feminist movements should reject feminist icons that are adversarial and embody violence.",
124
+ "THBT freedom of speech should be considered obsolete.",
125
+ "THR the narrative that eccentric personalities are essential to create art.",
126
+ "THW allow parents of severely mentally disabled children to medically impede their children's physical growth.",
127
+ "THR the emphasis on longevity in relationships.",
128
+ "Assuming feasibility, THW choose to continuously relive the happiest moment of one’s life."
129
  ]
130
+
131
+ st.session_state.topic = st.selectbox("Select a topic_list", topic_list)
132
+
133
+ #st.session_state.topic = topic#st.selectbox("Select a topic_list", topic_list)
134
+ #st.write(f"You have selected {st.session_state.topic_list}. Please input sound.")
135
+
136
+ if st.button(
137
+ label='Submit all information',
138
+ on_click=page_controller
139
+ ):
140
+ # You can add a function here to save the submitted info
141
+ if st.session_state.user_id != '' and st.session_state.openAI_token != '':
142
+ save_info(
143
+ st.session_state.user_id,
144
+ st.session_state.openAI_token,
145
+ st.session_state.debate_theme
146
+ )
147
+ st.write('Information submitted successfully.')
148
+
149
+ # Page 2
150
+ def page2():
151
+ st.header('Page 2')
152
+ tab1, tab2, tab3 = st.tabs(["Tab 1", "Tab 2", "Tab 3"])
153
+
154
+ with tab1:
155
+ st.header("Tab 1")
156
+
157
+ with tab2:
158
+ st.header("Tab 2")
159
+
160
+ with tab3:
161
+ st.header("Tab 3")
162
+
163
+ #st.write(f"You have selected {selected_tab}. Please input sound.")
164
+ # Insert the code to input sound using mike and convert to text
165
+
166
+
167
+ # Page Routing
168
+ pages = {
169
+ "Page 1": page1,
170
+ "Page 2": page2
171
+ }
172
+
173
+ # Nav Bar
174
+ # st.sidebar.title('Navigation')
175
+ #selection = st.sidebar.radio("Go to", list(pages.keys()))
176
+
177
+ selection = st.session_state.page
178
+
179
+ print("selection:", selection)
180
+
181
+ page = pages[selection]
182
+
183
+ # Execute selected page function
184
+ page()
185
+
186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vocal_app.sh ADDED
@@ -0,0 +1 @@
 
 
1
+ streamlit run vocal_app.py
vocal_app2.py DELETED
@@ -1,165 +0,0 @@
1
- import streamlit as st
2
- #import SessionState
3
-
4
- # Page Configuration
5
- st.set_page_config(page_title="Streamlit App")
6
-
7
- if "page" not in st.session_state:
8
- st.session_state.page = "Page 1"
9
-
10
- if "topic" not in st.session_state:
11
- st.session_state.topic = "None"
12
-
13
- # Save function (placeholder)
14
- def save_info(user_id, openAI_token, debate_theme):
15
- # You can add the code to save the submitted info (e.g., to a database)
16
- st.session_state.user_id = user_id,
17
- st.session_state.openAI_token = openAI_token,
18
- st.session_state.debate_theme = debate_theme
19
-
20
- # Session state
21
- #session_state = SessionState.get(user_id="", openAI_token="", debate_theme="")
22
-
23
- def write_info():
24
- st.write('You choose', st.session_state.topic_list)
25
-
26
- # for callback when button is clicked
27
- def page_controller():
28
- st.session_state.page = "Page 2"
29
-
30
-
31
- # Page 1
32
- def page1():
33
-
34
- # for local variables
35
- topic_list = []
36
-
37
- st.header('Page 1')
38
- st.session_state.user_id = st.text_input("Enter user ID")
39
- st.session_state.openAI_token = st.text_input("Enter OpenAI token")
40
- debate_themes = ['Education','Sports','Religion','Justice','Pandemic','Politics','Minority','etc']
41
- st.session_state.debate_theme = st.selectbox("Select a debate theme", debate_themes)
42
-
43
- if st.button(
44
- label='Select a debate theme!'
45
- #on_click=write_info
46
- ):
47
- if st.session_state.debate_theme == 'Education':
48
- topic_list = [
49
- "THBT college entrance examinations should accept students only on the basis of their academic performance in secondary education.",
50
- "THS a world where the government gives cash that individuals can use to freely select their academic preference (including but not limited to school of choice, private academies, and tutoring) instead of funding for public education.",
51
- "THW abolish all requirements and evaluation criteria in higher education (i.e., attendance, exams, assignments)."
52
- ]
53
- #topic = st.selectbox("Select a topic_list", topic_list)
54
- elif st.session_state.debate_theme == 'Sports':
55
- topic_list = [
56
- "THBT having star players for team sports do more harm than good to the team.",
57
- "THR the emphasis on winning a medal in the Olympics as a core symbol of success.",
58
- "THP a world where sports serves purely entertainment purposes even at the expense of fair play."
59
- ]
60
- #topic = st.selectbox("Select a topic_list", topic_list)
61
- elif st.session_state.debate_theme == 'Religion':
62
- topic_list = [
63
- "THW, as a religious group/leader, cease attempts at increasing the number of believers and instead prioritize boosting loyalty amongst adherents to the religion.",
64
- "Assuming feasibility, TH prefers a world where a panel of church leaders would create a universally accepted interpretation of the Bible that the believers would abide by.",
65
- "THW aggressively crackdown on megachurches."
66
- ]
67
- #topic = st.selectbox("Select a topic_list", topic_list)
68
- elif st.session_state.debate_theme == 'Justice':
69
- topic_list = [
70
- "In 2050, AI robots are able to replicate the appearance, conversation, and reaction to emotions of human beings. However, their intelligence still does not allow them to sense emotions and feelings such as pain, happiness, joy, and etc.",
71
- "In the case a human destroys the robot beyond repair, THW charge murder instead of property damage.",
72
- "THP a world where the criminal justice system’s role is mainly for victim’s vengeance. THW allow prosecutors and victims to veto assigned judges."
73
- ]
74
- #topic = st.selectbox("Select a topic_list", topic_list)
75
- elif st.session_state.debate_theme == 'Pandemic':
76
- topic_list = [
77
- "During a pandemic, THBT businesses that benefit from the pandemic should be additionally taxed.",
78
- "THW nullify the effect of medical patents in cases of medical emergencies.",
79
- "THW ban media content that denies the efficacy of the COVID-19 without substantial evidence."
80
- ]
81
- #topic = st.selectbox("Select a topic_list", topic_list)
82
- elif st.session_state.debate_theme == 'Politics':
83
- topic_list = [
84
- "Info: The Candle Light Will (촛불민심) is a term derived from the symbolic candle-light protests for the impeachment of the late president Park Geun Hye, commonly used to mean the people’s will to fight against corrupt governments. The Moon administration has frequently referred to the Candle Light Will as the driving force behind its election that grants legitimacy to its policies. THR the ‘candle light will’ narrative in the political discourse of South Korea.",
85
- "THW impose a cap on the property and income of politicians.",
86
- "THW give the youth extra votes."
87
- ]
88
- #topic = st.selectbox("Select a topic_list", topic_list)
89
- elif st.session_state.debate_theme == 'Minority':
90
- topic_list = [
91
- "Context: A prominent member of the LGBT movement has discovered that a very influential politician helping the LGBT movement has been lying about their sexual orientation as being gay when they are straight. THW disclose this information.",
92
- "THBT the LGBTQIA+ movement should denounce the existence of marriage as opposed to fighting for equal marriage rights.",
93
- "THBT the LGBTQIA+ movement should condemn the consumption of movies and TV shows that cast straight actors/actresses in non-heterosexual identified roles."
94
- ]
95
- #topic = st.selectbox("Select a topic_list", topic_list)
96
- else:
97
- topic_list = [
98
- "THW remove all laws that relate to filial responsibilities.",
99
- "THW require parents to receive approval from experts in relevant fields before making crucial decisions for their children.",
100
- "Assuming it is possible to measure the ‘societal danger’ of the fetus in the future, THBT the state should raise infants that pose high levels of threat.",
101
- "THBT any upper limits on prison sentences for particularly heinous crimes should be abolished.",
102
- "THW require dating apps to anonymize profile pictures.",
103
- "THW adopt a Pass/Fail grading system for students who suffer from mental health problems (e.g. depression, bipolar disorder, etc.).",
104
- "THBT South Korean feminist movements should reject feminist icons that are adversarial and embody violence.",
105
- "THBT freedom of speech should be considered obsolete.",
106
- "THR the narrative that eccentric personalities are essential to create art.",
107
- "THW allow parents of severely mentally disabled children to medically impede their children's physical growth.",
108
- "THR the emphasis on longevity in relationships.",
109
- "Assuming feasibility, THW choose to continuously relive the happiest moment of one’s life."
110
- ]
111
-
112
- st.session_state.topic = st.selectbox("Select a topic_list", topic_list)
113
-
114
- #st.session_state.topic = topic#st.selectbox("Select a topic_list", topic_list)
115
- #st.write(f"You have selected {st.session_state.topic_list}. Please input sound.")
116
-
117
- if st.button(
118
- label='Submit all information',
119
- on_click=page_controller
120
- ):
121
- # You can add a function here to save the submitted info
122
- save_info(
123
- st.session_state.user_id,
124
- st.session_state.openAI_token,
125
- st.session_state.debate_theme
126
- )
127
- st.write('Information submitted successfully.')
128
-
129
- # Page 2
130
- def page2():
131
- st.header('Page 2')
132
- tab1, tab2, tab3 = st.tabs(["Tab 1", "Tab 2", "Tab 3"])
133
-
134
- with tab1:
135
- st.header("Tab 1")
136
-
137
- with tab2:
138
- st.header("Tab 2")
139
-
140
- with tab3:
141
- st.header("Tab 3")
142
-
143
- #st.write(f"You have selected {selected_tab}. Please input sound.")
144
- # Insert the code to input sound using mike and convert to text
145
-
146
-
147
- # Page Routing
148
- pages = {
149
- "Page 1": page1,
150
- "Page 2": page2
151
- }
152
-
153
- st.sidebar.title('Navigation')
154
- #selection = st.sidebar.radio("Go to", list(pages.keys()))
155
-
156
- selection = st.session_state.page
157
-
158
- print("selection:", selection)
159
-
160
- page = pages[selection]
161
-
162
- # Execute selected page function
163
- page()
164
-
165
-