Turbiling commited on
Commit
bdd7e7e
·
verified ·
1 Parent(s): b7c3a5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -63,9 +63,10 @@ def remove_emojis_and_special_chars(text):
63
 
64
  text = emoji_pattern.sub(r'', text)
65
  # Keep Urdu, English, numbers, and basic punctuation
66
- text = re.sub(r'[^\w\s\-.,;:!?()\[\]{}\'\"\/\n\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF]', '', text)
67
  return text
68
 
 
69
  def add_page_numbers(section):
70
  """Add page numbers to document footer"""
71
  footer = section.footer
@@ -88,6 +89,7 @@ def add_page_numbers(section):
88
  run._r.append(instrText)
89
  run._r.append(fldChar2)
90
 
 
91
  def is_urdu_text(text):
92
  """Check if text contains Urdu characters"""
93
  urdu_pattern = re.compile(r'[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF]')
@@ -142,7 +144,8 @@ def transcribe_audio_chunked(audio_path):
142
  response_format="verbose_json"
143
  )
144
 
145
- chunk_text = transcription.text.strip()
 
146
  if chunk_text:
147
  all_transcriptions.append(chunk_text)
148
 
@@ -175,6 +178,7 @@ Ensure the text flows naturally and coherently:
175
  print(f"Transcription error details: {traceback.format_exc()}")
176
  return None, error_msg
177
 
 
178
  def transcribe_single_audio(audio_path):
179
  """Transcribe a single audio file"""
180
  with open(audio_path, "rb") as audio_file:
@@ -185,7 +189,8 @@ def transcribe_single_audio(audio_path):
185
  response_format="verbose_json"
186
  )
187
 
188
- text = transcription.text.strip()
 
189
 
190
  if not text:
191
  return None, "❌ Transcription returned empty text"
@@ -523,6 +528,7 @@ def create_docx(content, title, institution_name="", writer_name="", language="E
523
  print(f"DOCX creation error: {traceback.format_exc()}")
524
  raise e
525
 
 
526
  def create_pptx(content, title, language="English"):
527
  """
528
  Create PowerPoint presentation with images, charts, and professional design
@@ -697,7 +703,7 @@ def generate_and_download(text, content_type, language, institution_name, writer
697
  # Generate content
698
  content = generate_content(text, content_type, language)
699
 
700
- if content.startswith("❌"):
701
  return content, None, content
702
 
703
  # Create document
@@ -742,7 +748,7 @@ def generate_pptx_only(text, language, institution_name, writer_name):
742
  try:
743
  content = generate_content(text, "powerpoint", language)
744
 
745
- if content.startswith("❌"):
746
  return None, content
747
 
748
  ppt_title = "Presentation" if language == "English" else "پیشکش"
@@ -760,9 +766,8 @@ def generate_pptx_only(text, language, institution_name, writer_name):
760
  # =================================================================================
761
 
762
  with gr.Blocks() as app:
763
-
764
  # ===== HEADER =====
765
- gr.Markdown("""
766
  # 🎙️ Professional Voice Transcription & Content Generation System
767
  ### Transform your audio into professional documents, presentations, and educational content
768
  **Supports:** Urdu & English | **Features:** 15+ Content Types | **Export:** DOCX & PPTX
@@ -774,4 +779,10 @@ with gr.Blocks() as app:
774
  1. **Record or Upload:** Upload your lecture, seminar, or educational discussion audio. The system handles long recordings automatically by processing them in chunks.
775
  2. **Review Transcription:** Once transcribed, review the text for accuracy. You can copy and edit if needed before generating content.
776
  3. **Generate Educational Materials:** Select your desired content type (study notes, quiz questions, summaries) and language preference. The system will create professional documents ready for classroom use or student distribution.
777
- """)
 
 
 
 
 
 
 
63
 
64
  text = emoji_pattern.sub(r'', text)
65
  # Keep Urdu, English, numbers, and basic punctuation
66
+ text = re.sub(r'[^\w\s\-.,;:!?()\[\]{}\'"\/\n\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF]', '', text)
67
  return text
68
 
69
+
70
  def add_page_numbers(section):
71
  """Add page numbers to document footer"""
72
  footer = section.footer
 
89
  run._r.append(instrText)
90
  run._r.append(fldChar2)
91
 
92
+
93
  def is_urdu_text(text):
94
  """Check if text contains Urdu characters"""
95
  urdu_pattern = re.compile(r'[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF]')
 
144
  response_format="verbose_json"
145
  )
146
 
147
+ chunk_text = getattr(transcription, 'text', None) or transcription.get('text', '')
148
+ chunk_text = chunk_text.strip() if chunk_text else ''
149
  if chunk_text:
150
  all_transcriptions.append(chunk_text)
151
 
 
178
  print(f"Transcription error details: {traceback.format_exc()}")
179
  return None, error_msg
180
 
181
+
182
  def transcribe_single_audio(audio_path):
183
  """Transcribe a single audio file"""
184
  with open(audio_path, "rb") as audio_file:
 
189
  response_format="verbose_json"
190
  )
191
 
192
+ text = getattr(transcription, 'text', None) or transcription.get('text', '')
193
+ text = text.strip() if text else ''
194
 
195
  if not text:
196
  return None, "❌ Transcription returned empty text"
 
528
  print(f"DOCX creation error: {traceback.format_exc()}")
529
  raise e
530
 
531
+
532
  def create_pptx(content, title, language="English"):
533
  """
534
  Create PowerPoint presentation with images, charts, and professional design
 
703
  # Generate content
704
  content = generate_content(text, content_type, language)
705
 
706
+ if isinstance(content, str) and content.startswith("❌"):
707
  return content, None, content
708
 
709
  # Create document
 
748
  try:
749
  content = generate_content(text, "powerpoint", language)
750
 
751
+ if isinstance(content, str) and content.startswith("❌"):
752
  return None, content
753
 
754
  ppt_title = "Presentation" if language == "English" else "پیشکش"
 
766
  # =================================================================================
767
 
768
  with gr.Blocks() as app:
 
769
  # ===== HEADER =====
770
+ gr.Markdown("""
771
  # 🎙️ Professional Voice Transcription & Content Generation System
772
  ### Transform your audio into professional documents, presentations, and educational content
773
  **Supports:** Urdu & English | **Features:** 15+ Content Types | **Export:** DOCX & PPTX
 
779
  1. **Record or Upload:** Upload your lecture, seminar, or educational discussion audio. The system handles long recordings automatically by processing them in chunks.
780
  2. **Review Transcription:** Once transcribed, review the text for accuracy. You can copy and edit if needed before generating content.
781
  3. **Generate Educational Materials:** Select your desired content type (study notes, quiz questions, summaries) and language preference. The system will create professional documents ready for classroom use or student distribution.
782
+ """)
783
+
784
+ # (NOTE) Add more UI components (inputs, buttons, outputs) below as needed.
785
+
786
+ # Launch the app when executed directly
787
+ if __name__ == "__main__":
788
+ app.launch()