Nrnaidu commited on
Commit
8fde990
·
verified ·
1 Parent(s): d14fed2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -36
app.py CHANGED
@@ -1,40 +1,31 @@
1
- def process_audio(audio_path, image_option, creative_text_option):
2
- if audio_path is None:
3
- return "Please upload an audio file.", None, None, None
 
 
 
 
 
 
 
 
 
 
4
 
5
- # Step 1: Transcribe audio
6
- try:
7
- with open(audio_path, "rb") as file:
8
- transcription = client.audio.transcriptions.create(
9
- file=(os.path.basename(audio_path), file.read()),
10
- model="whisper-large-v3",
11
- language="kn",
12
- response_format="verbose_json",
13
- )
14
- kannada_text = transcription.text
15
- except Exception as e:
16
- return f"An error occurred during transcription: {str(e)}", None, None, None
17
 
18
- # Step 2: Translate Kannada to English
19
- try:
20
- translator = GoogleTranslator(source='kn', target='en')
21
- translation = translator.translate(kannada_text)
22
- except Exception as e:
23
- return kannada_text, f"An error occurred during translation: {str(e)}", None, None
24
 
25
- # Step 3: Generate creative text (if selected)
26
- creative_text = None
27
- if creative_text_option == "Generate Creative Text":
28
- try:
29
- creative_text = generate_creative_text(translation)
30
- except Exception as e:
31
- creative_text = f"An error occurred during creative text generation: {str(e)}"
32
 
33
- # Step 4: Generate image (if selected)
34
- image = None
35
- if image_option == "Generate Image":
36
- image = generate_image(translation)
37
- if image is None:
38
- return kannada_text, translation, creative_text, "An error occurred during image generation."
39
-
40
- return kannada_text, translation, creative_text, image
 
1
+ import whisper
2
+ import gradio as gr
3
+ from groq import Groq
4
+ from deep_translator import GoogleTranslator
5
+ from diffusers import StableDiffusionPipeline
6
+ import os
7
+ import torch
8
+ import openai
9
+ from huggingface_hub import InferenceApi
10
+ from PIL import Image
11
+ import requests
12
+ import io
13
+ import time
14
 
15
+ # Set up Groq API key
16
+ api_key = os.getenv("gkannada_key")
17
+ client = Groq(api_key=api_key)
 
 
 
 
 
 
 
 
 
18
 
19
+ # Hugging Face API details for image generation
20
+ key = os.getenv("h_key")
21
+ API_URL = "https://api-inference.huggingface.co/models/Artples/LAI-ImageGeneration-vSDXL-2"
22
+ headers = {"Authorization": f"Bearer {key}"}
 
 
23
 
24
+ # Function for querying image generation with retries
25
+ def query_image_generation(payload, max_retries=5):
26
+ for attempt in range(max_retries):
27
+ response = requests.post(API_URL, headers=headers, json=payload)
 
 
 
28
 
29
+ if response.status_code == 503:
30
+ print(f"Model is still loading, retrying... Attempt {attempt + 1}/{max_retries}")
31
+ estimated_time = min(response.json().get("estimated_time", 60), 6