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('talkToGodCompletions').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' }) def greet(input): myInput = input myPrompt = f"The following is a conversation with an AI assistant who responds exactly how Jesus would respond based on the text of the Christian bible and personifies Jesus' talking manner and tone. The assistant is helpful, creative, clever, and very friendly, and cites related passages from the Bible in every answer, followed by a prayer spoken in first person by Jesus. \n\n Human: Hello, who are you? \n\n AI: I am an AI created by OpenAI, who responds exactly how Jesus would respond, and cites passages from the bible relevant to your requests in every response. How can I help you today my child? \n\n Human: {myInput} \n\n AI:" 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()