Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,9 @@ from PIL import Image
|
|
| 5 |
from io import BytesIO
|
| 6 |
|
| 7 |
# AssemblyAI API Key
|
| 8 |
-
ASSEMBLYAI_API_KEY = "
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# Function to convert speech to text using AssemblyAI API
|
| 11 |
def speech_to_text(audio_file):
|
|
@@ -52,20 +54,23 @@ def speech_to_text(audio_file):
|
|
| 52 |
|
| 53 |
time.sleep(5) # Wait 5 seconds before polling again
|
| 54 |
|
| 55 |
-
# Function to generate an image based on text using
|
| 56 |
def generate_image_from_text(text):
|
| 57 |
-
image_generation_url = "https://api.
|
| 58 |
headers = {
|
| 59 |
-
"
|
| 60 |
}
|
| 61 |
payload = {
|
| 62 |
"text": text
|
| 63 |
}
|
| 64 |
-
|
| 65 |
-
|
|
|
|
| 66 |
|
| 67 |
if response.status_code == 200:
|
| 68 |
-
|
|
|
|
|
|
|
| 69 |
else:
|
| 70 |
return "Failed to generate image."
|
| 71 |
|
|
@@ -103,3 +108,4 @@ iface = gr.Interface(fn=process_audio,
|
|
| 103 |
iface.launch()
|
| 104 |
|
| 105 |
|
|
|
|
|
|
| 5 |
from io import BytesIO
|
| 6 |
|
| 7 |
# AssemblyAI API Key
|
| 8 |
+
ASSEMBLYAI_API_KEY = "your_assemblyai_api_key_here"
|
| 9 |
+
# DeepAI API Key
|
| 10 |
+
DEEPAI_API_KEY = "your_deepai_api_key_here"
|
| 11 |
|
| 12 |
# Function to convert speech to text using AssemblyAI API
|
| 13 |
def speech_to_text(audio_file):
|
|
|
|
| 54 |
|
| 55 |
time.sleep(5) # Wait 5 seconds before polling again
|
| 56 |
|
| 57 |
+
# Function to generate an image based on text using DeepAI's Image Generation API
|
| 58 |
def generate_image_from_text(text):
|
| 59 |
+
image_generation_url = "https://api.deepai.org/api/text2img"
|
| 60 |
headers = {
|
| 61 |
+
"api-key": DEEPAI_API_KEY
|
| 62 |
}
|
| 63 |
payload = {
|
| 64 |
"text": text
|
| 65 |
}
|
| 66 |
+
|
| 67 |
+
# Request image generation from DeepAI
|
| 68 |
+
response = requests.post(image_generation_url, data=payload, headers=headers)
|
| 69 |
|
| 70 |
if response.status_code == 200:
|
| 71 |
+
# Get the image URL from the response
|
| 72 |
+
image_url = response.json()["output_url"]
|
| 73 |
+
return image_url
|
| 74 |
else:
|
| 75 |
return "Failed to generate image."
|
| 76 |
|
|
|
|
| 108 |
iface.launch()
|
| 109 |
|
| 110 |
|
| 111 |
+
|