Spaces:
Configuration error
Configuration error
aasherkamal216
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,7 @@ import json
|
|
| 10 |
from utils import set_safety_settings, about, speech_to_text
|
| 11 |
import google.generativeai as genai
|
| 12 |
import os, random, validators
|
|
|
|
| 13 |
import tempfile
|
| 14 |
import asyncio
|
| 15 |
import edge_tts
|
|
@@ -140,7 +141,18 @@ def messages_to_gemini(messages):
|
|
| 140 |
temp_file_path = base64_to_temp_file(content[content_type], file_name, "mp4" if content_type == "video_file" else "wav")
|
| 141 |
|
| 142 |
with st.spinner(f"Sending {content_type.replace('_', ' ')} to Gemini..."):
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
os.remove(temp_file_path)
|
| 145 |
|
| 146 |
elif content_type == "pdf_file":
|
|
|
|
| 10 |
from utils import set_safety_settings, about, speech_to_text
|
| 11 |
import google.generativeai as genai
|
| 12 |
import os, random, validators
|
| 13 |
+
import time
|
| 14 |
import tempfile
|
| 15 |
import asyncio
|
| 16 |
import edge_tts
|
|
|
|
| 141 |
temp_file_path = base64_to_temp_file(content[content_type], file_name, "mp4" if content_type == "video_file" else "wav")
|
| 142 |
|
| 143 |
with st.spinner(f"Sending {content_type.replace('_', ' ')} to Gemini..."):
|
| 144 |
+
file = genai.upload_file(path=temp_file_path)
|
| 145 |
+
|
| 146 |
+
while file.state.name == "PROCESSING":
|
| 147 |
+
st.write(':green[One moment, please.]')
|
| 148 |
+
time.sleep(10)
|
| 149 |
+
file = genai.get_file(file.name)
|
| 150 |
+
|
| 151 |
+
if file.state.name == "FAILED":
|
| 152 |
+
raise ValueError(file.state.name)
|
| 153 |
+
|
| 154 |
+
file = genai.get_file(name=file.name)
|
| 155 |
+
gemini_message["parts"].append(file)
|
| 156 |
os.remove(temp_file_path)
|
| 157 |
|
| 158 |
elif content_type == "pdf_file":
|