Spaces:
No application file
No application file
Update app.py
Browse files
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
|
| 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
|
| 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,
|
| 117 |
-
|
| 118 |
-
#
|
| 119 |
-
with
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|