Turbiling commited on
Commit
3e2e4c6
·
verified ·
1 Parent(s): 065506d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -31
app.py CHANGED
@@ -46,7 +46,7 @@ def transcribe_and_rewrite(audio):
46
  # -----------------------------
47
  # Action Functions
48
  # -----------------------------
49
- def perform_action(action, text):
50
  if not text:
51
  return "❌ No transcribed text available. Upload or record audio first."
52
 
@@ -64,7 +64,7 @@ def perform_action(action, text):
64
  "Infographic Content": f"Create infographic content from the text below:\n\n{text}"
65
  }
66
 
67
- prompt = prompts.get(action, f"Process the text: {text}")
68
  completion = client.chat.completions.create(
69
  model="openai/gpt-oss-120b",
70
  messages=[{"role": "user", "content": prompt}],
@@ -95,26 +95,11 @@ with gr.Blocks() as app:
95
 
96
  output_text = gr.Textbox(label="Transcribed & Rewritten Text", lines=15)
97
  status_msg = gr.Markdown("")
98
-
99
- # Post-transcription action buttons
100
- with gr.Row():
101
- themes_btn = gr.Button("1️⃣ Themes & Subthemes")
102
- minutes_btn = gr.Button("2️⃣ Minutes of Meeting")
103
- summary_btn = gr.Button("3️⃣ Summary")
104
- tutorial_btn = gr.Button("4️⃣ Tutorials for Beginners")
105
-
106
- with gr.Row():
107
- ppt_btn = gr.Button("5️⃣ PowerPoint Slides")
108
- notes_btn = gr.Button("6️⃣ Study Notes")
109
- social_btn = gr.Button("7️⃣ Social Media Post")
110
- quiz_btn = gr.Button("8️⃣ Quiz Questions")
111
-
112
- with gr.Row():
113
- translate_btn = gr.Button("9️⃣ Translation")
114
- infographic_btn = gr.Button("🔟 Infographic Content")
115
-
116
  action_output = gr.Textbox(label="Action Output", lines=15)
117
 
 
 
 
118
  # Automatically transcribe when audio changes
119
  audio_input.change(
120
  transcribe_and_rewrite,
@@ -129,16 +114,25 @@ with gr.Blocks() as app:
129
  outputs=[audio_input, output_text, status_msg, action_output]
130
  )
131
 
132
- # Link action buttons
133
- themes_btn.click(perform_action, inputs=["Themes & Subthemes", output_text], outputs=[action_output])
134
- minutes_btn.click(perform_action, inputs=["Minutes of Meeting", output_text], outputs=[action_output])
135
- summary_btn.click(perform_action, inputs=["Summary", output_text], outputs=[action_output])
136
- tutorial_btn.click(perform_action, inputs=["Tutorials for Beginners", output_text], outputs=[action_output])
137
- ppt_btn.click(perform_action, inputs=["PowerPoint Slides", output_text], outputs=[action_output])
138
- notes_btn.click(perform_action, inputs=["Study Notes", output_text], outputs=[action_output])
139
- social_btn.click(perform_action, inputs=["Social Media Post", output_text], outputs=[action_output])
140
- quiz_btn.click(perform_action, inputs=["Quiz Questions", output_text], outputs=[action_output])
141
- translate_btn.click(perform_action, inputs=["Translation", output_text], outputs=[action_output])
142
- infographic_btn.click(perform_action, inputs=["Infographic Content", output_text], outputs=[action_output])
 
 
 
 
 
 
 
 
 
143
 
144
  app.launch()
 
46
  # -----------------------------
47
  # Action Functions
48
  # -----------------------------
49
+ def perform_action(action_name, text):
50
  if not text:
51
  return "❌ No transcribed text available. Upload or record audio first."
52
 
 
64
  "Infographic Content": f"Create infographic content from the text below:\n\n{text}"
65
  }
66
 
67
+ prompt = prompts.get(action_name, f"Process the text: {text}")
68
  completion = client.chat.completions.create(
69
  model="openai/gpt-oss-120b",
70
  messages=[{"role": "user", "content": prompt}],
 
95
 
96
  output_text = gr.Textbox(label="Transcribed & Rewritten Text", lines=15)
97
  status_msg = gr.Markdown("")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  action_output = gr.Textbox(label="Action Output", lines=15)
99
 
100
+ # Store action selection in a hidden state
101
+ action_name = gr.State()
102
+
103
  # Automatically transcribe when audio changes
104
  audio_input.change(
105
  transcribe_and_rewrite,
 
114
  outputs=[audio_input, output_text, status_msg, action_output]
115
  )
116
 
117
+ # Helper to call perform_action with a string
118
+ def run_action(action_str):
119
+ return perform_action(action_str, output_text.value)
120
+
121
+ # Action Buttons
122
+ with gr.Row():
123
+ gr.Button("1️⃣ Themes & Subthemes").click(run_action, inputs=[], outputs=[action_output], _js=None, kwargs={"action_str": "Themes & Subthemes"})
124
+ gr.Button("2️⃣ Minutes of Meeting").click(run_action, inputs=[], outputs=[action_output], _js=None, kwargs={"action_str": "Minutes of Meeting"})
125
+ gr.Button("3️⃣ Summary").click(run_action, inputs=[], outputs=[action_output], _js=None, kwargs={"action_str": "Summary"})
126
+ gr.Button("4️⃣ Tutorials for Beginners").click(run_action, inputs=[], outputs=[action_output], _js=None, kwargs={"action_str": "Tutorials for Beginners"})
127
+
128
+ with gr.Row():
129
+ gr.Button("5️⃣ PowerPoint Slides").click(run_action, inputs=[], outputs=[action_output], _js=None, kwargs={"action_str": "PowerPoint Slides"})
130
+ gr.Button("6️⃣ Study Notes").click(run_action, inputs=[], outputs=[action_output], _js=None, kwargs={"action_str": "Study Notes"})
131
+ gr.Button("7️⃣ Social Media Post").click(run_action, inputs=[], outputs=[action_output], _js=None, kwargs={"action_str": "Social Media Post"})
132
+ gr.Button("8️⃣ Quiz Questions").click(run_action, inputs=[], outputs=[action_output], _js=None, kwargs={"action_str": "Quiz Questions"})
133
+
134
+ with gr.Row():
135
+ gr.Button("9️⃣ Translation").click(run_action, inputs=[], outputs=[action_output], _js=None, kwargs={"action_str": "Translation"})
136
+ gr.Button("🔟 Infographic Content").click(run_action, inputs=[], outputs=[action_output], _js=None, kwargs={"action_str": "Infographic Content"})
137
 
138
  app.launch()