Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,14 +6,24 @@ from deep_translator import GoogleTranslator
|
|
6 |
from diffusers import StableDiffusionPipeline
|
7 |
import torch
|
8 |
import huggingface_hub
|
|
|
9 |
|
10 |
-
#
|
11 |
api_key = os.getenv("GROQ_API_KEY")
|
12 |
client = Groq(api_key=api_key)
|
13 |
|
14 |
-
#
|
15 |
-
HF_API_KEY =
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
# Set device: CUDA if available, else CPU
|
19 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
@@ -24,16 +34,7 @@ whisper_model = whisper.load_model("base")
|
|
24 |
# Model IDs for Stable Diffusion pipelines
|
25 |
model_id1 = "dreamlike-art/dreamlike-diffusion-1.0"
|
26 |
model_id2 = "stabilityai/stable-diffusion-xl-base-1.0"
|
27 |
-
restricted_model_id = "ByteDance/SDXL-Lightning" # Model
|
28 |
-
|
29 |
-
# # Initialize Stable Diffusion pipeline based on device
|
30 |
-
# if torch.cuda.is_available():
|
31 |
-
# pipe = StableDiffusionPipeline.from_pretrained(model_id2, torch_dtype=torch.float16)
|
32 |
-
# else:
|
33 |
-
# pipe = StableDiffusionPipeline.from_pretrained(model_id2) # Omit torch_dtype for CPU
|
34 |
-
|
35 |
-
# # Move model to the selected device (either GPU or CPU)
|
36 |
-
# pipe = pipe.to(device)
|
37 |
|
38 |
# Function to transcribe, translate, and analyze sentiment
|
39 |
def process_audio(audio_path, image_option):
|
|
|
6 |
from diffusers import StableDiffusionPipeline
|
7 |
import torch
|
8 |
import huggingface_hub
|
9 |
+
from huggingface_hub import login
|
10 |
|
11 |
+
# Set up Groq API key
|
12 |
api_key = os.getenv("GROQ_API_KEY")
|
13 |
client = Groq(api_key=api_key)
|
14 |
|
15 |
+
# Retrieve Hugging Face API key from environment variable
|
16 |
+
HF_API_KEY = os.getenv("HF_API_KEY")
|
17 |
+
|
18 |
+
if HF_API_KEY is None:
|
19 |
+
raise ValueError("Hugging Face API key not found. Please set it as an environment variable.")
|
20 |
+
|
21 |
+
# Login to Hugging Face
|
22 |
+
try:
|
23 |
+
login(HF_API_KEY)
|
24 |
+
print("Login successful!")
|
25 |
+
except Exception as e:
|
26 |
+
print(f"Error during Hugging Face login: {str(e)}")
|
27 |
|
28 |
# Set device: CUDA if available, else CPU
|
29 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
|
|
34 |
# Model IDs for Stable Diffusion pipelines
|
35 |
model_id1 = "dreamlike-art/dreamlike-diffusion-1.0"
|
36 |
model_id2 = "stabilityai/stable-diffusion-xl-base-1.0"
|
37 |
+
restricted_model_id = "ByteDance/SDXL-Lightning" # Model to access using HF_API_KEY
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
# Function to transcribe, translate, and analyze sentiment
|
40 |
def process_audio(audio_path, image_option):
|