k2s0 commited on
Commit
0275e43
1 Parent(s): 73dafbf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ import openai
4
+ import gradio as gr
5
+ import firebase_admin
6
+ from firebase_admin import credentials, firestore
7
+
8
+ # Get the service account key from the environment variable
9
+ service_account_key = os.environ["firebasekey"]
10
+
11
+ # Parse the service account key into a dictionary
12
+ service_account_info = json.loads(service_account_key)
13
+
14
+ # Create a Certificate object from the service account info
15
+ cred = credentials.Certificate(service_account_info)
16
+
17
+ # Initialize the Firebase Admin SDK
18
+ firebase_admin.initialize_app(cred)
19
+
20
+ # # Create a reference to the Firestore database
21
+ db = firestore.client()
22
+
23
+ openai.api_key = os.environ.get("openai_api_key")
24
+
25
+ def store_message(user_input, completion):
26
+ new_completion = db.collection('prayerGeneratorCompletions').document()
27
+ new_completion.set({
28
+ 'user_input': user_input,
29
+ 'completion': completion,
30
+ 'created_time': firestore.SERVER_TIMESTAMP,
31
+ 'model': 'text-davinci-003',
32
+ 'temperature': 0.7,
33
+ 'title': 'Talk to God'
34
+ })
35
+
36
+ # Prayer generator
37
+ def greet(input):
38
+
39
+ myInput = input
40
+ 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:"
41
+ response = openai.Completion.create(
42
+ model="text-davinci-003",
43
+ prompt=myPrompt,
44
+ temperature=0.7,
45
+ max_tokens=3000,
46
+ top_p=1.0,
47
+ frequency_penalty=0.0,
48
+ presence_penalty=0.0
49
+ )
50
+ raw_response = response['choices'][0]['text']
51
+ print(raw_response)
52
+ store_message(myInput, raw_response)
53
+ return raw_response
54
+
55
+
56
+ demo = gr.Interface(fn=greet, inputs="text", outputs="text")
57
+
58
+ demo.launch()