Turbiling commited on
Commit
8097bfb
·
verified ·
1 Parent(s): 5575451

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -33
app.py CHANGED
@@ -44,27 +44,30 @@ def transcribe_and_rewrite(audio):
44
  return "", f"❌ Error: {str(e)}"
45
 
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
 
 
 
 
53
  try:
54
  prompts = {
55
- "Themes & Subthemes": f"Act as a qualitative researcher and generate all possible themes and subthemes from the text below:\n\n{text}",
56
- "Minutes of Meeting": f"Create professional minutes of meeting from the text below suitable for MS Word:\n\n{text}",
57
- "Summary": f"Summarize the text below in clear and concise language:\n\n{text}",
58
- "Tutorials for Beginners": f"Create step-by-step tutorials for absolute beginners from the text below:\n\n{text}",
59
- "PowerPoint Slides": f"Create PowerPoint slide content from the text below, highlighting key points for each slide:\n\n{text}",
60
- "Study Notes": f"Make organized study notes from the text below:\n\n{text}",
61
- "Social Media Post": f"Write social media posts (engaging and short) from the text below:\n\n{text}",
62
- "Quiz Questions": f"Generate multiple-choice quiz questions from the text below:\n\n{text}",
63
- "Translation": f"Translate the text below into Urdu and English clearly:\n\n{text}",
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}],
@@ -111,25 +114,41 @@ with gr.Blocks() as app:
111
  outputs=[audio_input, output_text, status_msg, action_output]
112
  )
113
 
114
- # Helper to run action
115
- def run_action(action_str):
116
- return perform_action(action_str, output_text.value)
117
-
118
- # Action Buttons
119
- with gr.Row():
120
- gr.Button("1️⃣ Themes & Subthemes").click(lambda: run_action("Themes & Subthemes"), outputs=[action_output])
121
- gr.Button("2️⃣ Minutes of Meeting").click(lambda: run_action("Minutes of Meeting"), outputs=[action_output])
122
- gr.Button("3️⃣ Summary").click(lambda: run_action("Summary"), outputs=[action_output])
123
- gr.Button("4️⃣ Tutorials for Beginners").click(lambda: run_action("Tutorials for Beginners"), outputs=[action_output])
124
-
125
- with gr.Row():
126
- gr.Button("5️⃣ PowerPoint Slides").click(lambda: run_action("PowerPoint Slides"), outputs=[action_output])
127
- gr.Button("6️⃣ Study Notes").click(lambda: run_action("Study Notes"), outputs=[action_output])
128
- gr.Button("7️⃣ Social Media Post").click(lambda: run_action("Social Media Post"), outputs=[action_output])
129
- gr.Button("8️⃣ Quiz Questions").click(lambda: run_action("Quiz Questions"), outputs=[action_output])
130
-
131
- with gr.Row():
132
- gr.Button("9️⃣ Translation").click(lambda: run_action("Translation"), outputs=[action_output])
133
- gr.Button("🔟 Infographic Content").click(lambda: run_action("Infographic Content"), outputs=[action_output])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
 
135
  app.launch()
 
44
  return "", f"❌ Error: {str(e)}"
45
 
46
  # -----------------------------
47
+ # Action Functions with Language Option
48
  # -----------------------------
49
+ def perform_action(action_name, text, language):
50
  if not text:
51
  return "❌ No transcribed text available. Upload or record audio first."
52
 
53
+ if language not in ["English", "Urdu"]:
54
+ language = "English"
55
+
56
  try:
57
  prompts = {
58
+ "Themes & Subthemes": f"Act as a qualitative researcher and generate all possible themes and subthemes from the text below in {language}:\n\n{text}",
59
+ "Minutes of Meeting": f"Create professional minutes of meeting from the text below in {language}, suitable for MS Word:\n\n{text}",
60
+ "Summary": f"Summarize the text below in {language} clearly and concisely:\n\n{text}",
61
+ "Tutorials for Beginners": f"Create step-by-step tutorials for absolute beginners from the text below in {language}:\n\n{text}",
62
+ "PowerPoint Slides": f"Create PowerPoint slide content from the text below in {language}, highlighting key points for each slide:\n\n{text}",
63
+ "Study Notes": f"Make organized study notes from the text below in {language}:\n\n{text}",
64
+ "Social Media Post": f"Write social media posts (engaging and short) from the text below in {language}:\n\n{text}",
65
+ "Quiz Questions": f"Generate multiple-choice quiz questions from the text below in {language}:\n\n{text}",
66
+ "Translation": f"Translate the text below into {language} clearly:\n\n{text}",
67
+ "Infographic Content": f"Create infographic content from the text below in {language}:\n\n{text}"
68
  }
69
 
70
+ prompt = prompts.get(action_name, f"Process the text in {language}: {text}")
71
  completion = client.chat.completions.create(
72
  model="openai/gpt-oss-120b",
73
  messages=[{"role": "user", "content": prompt}],
 
114
  outputs=[audio_input, output_text, status_msg, action_output]
115
  )
116
 
117
+ # Helper function to run action with language dropdown
118
+ def run_action(action_str, lang, text):
119
+ return perform_action(action_str, text, lang)
120
+
121
+ # -----------------------------
122
+ # Action Buttons with Language Dropdown
123
+ # -----------------------------
124
+ action_buttons = [
125
+ "Themes & Subthemes",
126
+ "Minutes of Meeting",
127
+ "Summary",
128
+ "Tutorials for Beginners",
129
+ "PowerPoint Slides",
130
+ "Study Notes",
131
+ "Social Media Post",
132
+ "Quiz Questions",
133
+ "Translation",
134
+ "Infographic Content"
135
+ ]
136
+
137
+ for i in range(0, len(action_buttons), 2):
138
+ with gr.Row():
139
+ for j in range(2):
140
+ if i+j < len(action_buttons):
141
+ action_name = action_buttons[i+j]
142
+ lang_dropdown = gr.Dropdown(
143
+ choices=["English", "Urdu"],
144
+ value="English",
145
+ label=f"Select Language for {action_name}"
146
+ )
147
+ btn = gr.Button(f"{i+j+1}️⃣ {action_name}")
148
+ btn.click(
149
+ run_action,
150
+ inputs=[gr.State(action_name), lang_dropdown, output_text],
151
+ outputs=[action_output]
152
+ )
153
 
154
  app.launch()