Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
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 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
|
|
|
|
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)}"
|