Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ from faster_whisper import WhisperModel
|
|
| 5 |
from gtts import gTTS
|
| 6 |
import os
|
| 7 |
import subprocess
|
| 8 |
-
from PIL import Image, ImageDraw, ImageFont
|
| 9 |
import random
|
| 10 |
import textwrap
|
| 11 |
import pkg_resources
|
|
@@ -17,7 +17,7 @@ import base64
|
|
| 17 |
GROQ_API_KEY = "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"
|
| 18 |
GROQ_MODEL = "llama3-70b-8192"
|
| 19 |
GROQ_API_URL = "https://api.groq.com/openai/v1/chat/completions"
|
| 20 |
-
IMAGE_GENERATION_API_URL = "https://api.openai.com/v1/images/
|
| 21 |
OPENAI_API_KEY = "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # Replace with your OpenAI key
|
| 22 |
|
| 23 |
# === Init Whisper ===
|
|
@@ -63,6 +63,7 @@ def generate_images_with_openai(prompt, num_images=1):
|
|
| 63 |
"prompt": prompt,
|
| 64 |
"n": num_images,
|
| 65 |
"size": "1024x1024", # You can adjust the size as needed
|
|
|
|
| 66 |
}
|
| 67 |
|
| 68 |
try:
|
|
@@ -77,6 +78,9 @@ def generate_images_with_openai(prompt, num_images=1):
|
|
| 77 |
except KeyError:
|
| 78 |
print(f"Error: Unexpected response format from OpenAI: {data}")
|
| 79 |
return None
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
def create_animated_explanation(text, audio_file):
|
| 82 |
"""
|
|
@@ -126,7 +130,13 @@ def create_animated_explanation(text, audio_file):
|
|
| 126 |
|
| 127 |
# Display sentence
|
| 128 |
for j, line in enumerate(lines):
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
d.text((text_x, y_start + j * 24), line, fill=(0, 0, 0), font=font)
|
| 131 |
|
| 132 |
# Add image if available
|
|
|
|
| 5 |
from gtts import gTTS
|
| 6 |
import os
|
| 7 |
import subprocess
|
| 8 |
+
from PIL import Image, ImageDraw, ImageFont
|
| 9 |
import random
|
| 10 |
import textwrap
|
| 11 |
import pkg_resources
|
|
|
|
| 17 |
GROQ_API_KEY = "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"
|
| 18 |
GROQ_MODEL = "llama3-70b-8192"
|
| 19 |
GROQ_API_URL = "https://api.groq.com/openai/v1/chat/completions"
|
| 20 |
+
IMAGE_GENERATION_API_URL = "https://api.openai.com/v1/images/generations" # Corrected URL for DALL-E 3
|
| 21 |
OPENAI_API_KEY = "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # Replace with your OpenAI key
|
| 22 |
|
| 23 |
# === Init Whisper ===
|
|
|
|
| 63 |
"prompt": prompt,
|
| 64 |
"n": num_images,
|
| 65 |
"size": "1024x1024", # You can adjust the size as needed
|
| 66 |
+
"response_format": "url" # Ensure we get URLs
|
| 67 |
}
|
| 68 |
|
| 69 |
try:
|
|
|
|
| 78 |
except KeyError:
|
| 79 |
print(f"Error: Unexpected response format from OpenAI: {data}")
|
| 80 |
return None
|
| 81 |
+
except Exception as e:
|
| 82 |
+
print(f"Error during image generation: {e}")
|
| 83 |
+
return None
|
| 84 |
|
| 85 |
def create_animated_explanation(text, audio_file):
|
| 86 |
"""
|
|
|
|
| 130 |
|
| 131 |
# Display sentence
|
| 132 |
for j, line in enumerate(lines):
|
| 133 |
+
try:
|
| 134 |
+
bbox = d.textbbox((0,0), line, font=font)
|
| 135 |
+
text_width = bbox[2] - bbox[0]
|
| 136 |
+
text_x = (640 - text_width) // 2
|
| 137 |
+
except AttributeError as e:
|
| 138 |
+
print(f"Pillow version error: {e}")
|
| 139 |
+
text_x = 10
|
| 140 |
d.text((text_x, y_start + j * 24), line, fill=(0, 0, 0), font=font)
|
| 141 |
|
| 142 |
# Add image if available
|