Shanulhaq's picture
Update app.py
29a5603 verified
raw
history blame
No virus
1.47 kB
import streamlit as st
from google.cloud import aiplatform
import os
import logging
import whisper
from gtts import gTTS
import tempfile
from pydub import AudioSegment
from groq import Groq, GroqError
# Set up Google Cloud credentials
def setup_google_cloud_credentials():
google_credentials_path = "/path/to/your-service-account-file.json"
if os.path.exists(google_credentials_path):
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = google_credentials_path
logging.info(f"Google Cloud credentials set from {google_credentials_path}")
else:
raise FileNotFoundError(f"Google Cloud credentials file not found at {google_credentials_path}")
# Initialize the client
def init_palm(api_key):
aiplatform.init(api_key=api_key)
# Function to generate responses
def generate_palm_response(prompt):
response = aiplatform.Model.predict(
model_name="gemini-1.5-flash",
instances=[{"prompt": prompt}]
)
return response.predictions[0]['content']
# Main code to run the application
if __name__ == "__main__":
try:
# Set up Google Cloud credentials
setup_google_cloud_credentials()
# Call the model
api_key = "your-google-api-key"
init_palm(api_key)
response = generate_palm_response("Heart health query...")
print(response)
# Streamlit app or other logic goes here...
except Exception as e:
logging.error(f"Error occurred: {e}")