lodhrangpt commited on
Commit
bbee055
·
verified ·
1 Parent(s): 14ee15c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -14
app.py CHANGED
@@ -15,11 +15,9 @@ def transcribe(audio_path):
15
  with open(audio_path, "rb") as audio_file:
16
  audio_data = audio_file.read()
17
 
18
- # Groq API endpoint for audio transcription
19
  groq_api_endpoint = "https://api.groq.com/openai/v1/audio/transcriptions"
20
-
21
  headers = {
22
- "Authorization": "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", # Replace with your actual API key
23
  }
24
 
25
  files = {
@@ -41,7 +39,7 @@ def transcribe(audio_path):
41
  else:
42
  error_msg = response.json().get("error", {}).get("message", "Unknown error.")
43
  print(f"API Error: {error_msg}")
44
- return None # Indicate failure
45
 
46
  # Function to generate notes and questions
47
  def generate_notes(transcript):
@@ -66,7 +64,7 @@ def generate_notes(transcript):
66
  pdf_path = create_pdf(transcript, long_questions, short_questions, mcqs)
67
  return pdf_path
68
 
69
- # Function to create and save PDF
70
  def create_pdf(transcript, long_questions, short_questions, mcqs):
71
  pdf = FPDF()
72
  pdf.add_page()
@@ -109,18 +107,24 @@ def create_pdf(transcript, long_questions, short_questions, mcqs):
109
 
110
  return pdf_path
111
 
112
- # Gradio interface
113
- def gradio_interface(audio_path):
114
- pdf_path = transcribe(audio_path)
115
- if pdf_path:
116
- return pdf_path
117
- else:
118
- return "Error: Unable to process the audio file. Please check the API key and try again."
 
 
 
 
 
119
 
 
120
  iface = gr.Interface(
121
- fn=gradio_interface,
122
  inputs=gr.Audio(type="filepath"),
123
- outputs=gr.File(label="Download PDF with Notes and Questions"),
124
  title="Voice to Text Converter and Notes Generator",
125
  )
126
 
 
15
  with open(audio_path, "rb") as audio_file:
16
  audio_data = audio_file.read()
17
 
 
18
  groq_api_endpoint = "https://api.groq.com/openai/v1/audio/transcriptions"
 
19
  headers = {
20
+ "Authorization": "Bearer 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", # Replace with your actual API key
21
  }
22
 
23
  files = {
 
39
  else:
40
  error_msg = response.json().get("error", {}).get("message", "Unknown error.")
41
  print(f"API Error: {error_msg}")
42
+ return create_error_pdf(f"API Error: {error_msg}")
43
 
44
  # Function to generate notes and questions
45
  def generate_notes(transcript):
 
64
  pdf_path = create_pdf(transcript, long_questions, short_questions, mcqs)
65
  return pdf_path
66
 
67
+ # Function to create a PDF for transcription and questions
68
  def create_pdf(transcript, long_questions, short_questions, mcqs):
69
  pdf = FPDF()
70
  pdf.add_page()
 
107
 
108
  return pdf_path
109
 
110
+ # Function to create an error PDF
111
+ def create_error_pdf(message):
112
+ pdf = FPDF()
113
+ pdf.add_page()
114
+ pdf.set_font("Arial", "B", 16)
115
+ pdf.cell(200, 10, "Error Report", ln=True, align="C")
116
+ pdf.set_font("Arial", "", 12)
117
+ pdf.multi_cell(0, 10, message)
118
+
119
+ error_pdf_path = "/mnt/data/error_report.pdf"
120
+ pdf.output(error_pdf_path)
121
+ return error_pdf_path
122
 
123
+ # Gradio interface
124
  iface = gr.Interface(
125
+ fn=transcribe,
126
  inputs=gr.Audio(type="filepath"),
127
+ outputs=gr.File(label="Download PDF with Notes or Error Report"),
128
  title="Voice to Text Converter and Notes Generator",
129
  )
130