saranbalan commited on
Commit
5c7b9f9
·
verified ·
1 Parent(s): abccd5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -30,15 +30,21 @@ else:
30
  # Move model to the selected device (either GPU or CPU)
31
  pipe = pipe.to(device)
32
 
33
- # Function to process audio (transcription, translation, image generation)
34
  def process_audio(audio_path, image_option):
35
  if audio_path is None:
36
  return "Please upload an audio file.", None, None, None
37
 
38
- # Step 1: Transcribe audio using Whisper
39
  try:
40
- transcription = whisper_model.transcribe(audio_path)
41
- tamil_text = transcription['text']
 
 
 
 
 
 
42
  except Exception as e:
43
  return f"An error occurred during transcription: {str(e)}", None, None, None
44
 
@@ -53,7 +59,9 @@ def process_audio(audio_path, image_option):
53
  image = None
54
  if image_option == "Generate Image":
55
  try:
56
- # Ensure the model runs on the correct device (GPU/CPU)
 
 
57
  image = pipe(translation).images[0]
58
  except Exception as e:
59
  return tamil_text, translation, f"An error occurred during image generation: {str(e)}"
 
30
  # Move model to the selected device (either GPU or CPU)
31
  pipe = pipe.to(device)
32
 
33
+ # Function to transcribe, translate, and analyze sentiment
34
  def process_audio(audio_path, image_option):
35
  if audio_path is None:
36
  return "Please upload an audio file.", None, None, None
37
 
38
+ # Step 1: Transcribe audio
39
  try:
40
+ with open(audio_path, "rb") as file:
41
+ transcription = client.audio.transcriptions.create(
42
+ file=(os.path.basename(audio_path), file.read()),
43
+ model="whisper-large-v3",
44
+ language="ta",
45
+ response_format="verbose_json",
46
+ )
47
+ tamil_text = transcription.text
48
  except Exception as e:
49
  return f"An error occurred during transcription: {str(e)}", None, None, None
50
 
 
59
  image = None
60
  if image_option == "Generate Image":
61
  try:
62
+ model_id1 = "dreamlike-art/dreamlike-diffusion-1.0"
63
+ pipe = StableDiffusionPipeline.from_pretrained(model_id1, torch_dtype=torch.float16, use_safetensors=True)
64
+ pipe = pipe.to("cuda")
65
  image = pipe(translation).images[0]
66
  except Exception as e:
67
  return tamil_text, translation, f"An error occurred during image generation: {str(e)}"