import os import json import openai import gradio as gr import firebase_admin from firebase_admin import credentials, firestore # Get the service account key from the environment variable service_account_key = os.environ["firebasekey"] # Parse the service account key into a dictionary service_account_info = json.loads(service_account_key) # Create a Certificate object from the service account info cred = credentials.Certificate(service_account_info) # Initialize the Firebase Admin SDK firebase_admin.initialize_app(cred) # # Create a reference to the Firestore database db = firestore.client() openai.api_key = os.environ.get("openai_api_key") def store_message(user_input, completion): new_completion = db.collection('prayerGeneratorCompletions').document() new_completion.set({ 'user_input': user_input, 'completion': completion, 'created_time': firestore.SERVER_TIMESTAMP, 'model': 'text-davinci-003', 'temperature': 0.7, 'title': 'Talk to God' }) # Prayer generator def greet(input): myInput = input myPrompt = f"Respond as a compassionate pastor with an in-depth christian prayer that address details of the prayer request, the setting, people inovlved. In your response cite a bible verse from the christian bible that is specifically relevant, and explain it's relevance.Then end the response with a closing prayer. Human: {myInput} \n\n Pastor:" response = openai.Completion.create( model="text-davinci-003", prompt=myPrompt, temperature=0.7, max_tokens=3000, top_p=1.0, frequency_penalty=0.0, presence_penalty=0.0 ) raw_response = response['choices'][0]['text'] print(raw_response) store_message(myInput, raw_response) return raw_response demo = gr.Interface(fn=greet, inputs="text", outputs="text") demo.launch()