Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,31 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 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 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
except Exception as e:
|
| 23 |
-
return kannada_text, f"An error occurred during translation: {str(e)}", None, None
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 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 |
-
|
| 34 |
-
|
| 35 |
-
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|