Update app.py
Browse files
app.py
CHANGED
@@ -1,66 +1,66 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import openai as ai
|
3 |
-
import os
|
4 |
-
import requests
|
5 |
-
|
6 |
-
def greet(prompt):
|
7 |
-
if "created you" in prompt or "made you" in prompt or "developed you" in prompt:
|
8 |
-
response = "I was created by Dawn Saju, Alwin Mathew, Sivai Bala, Bryan Godwin and Mohammed Zaim"
|
9 |
-
return response
|
10 |
-
else:
|
11 |
-
ai.api_key = os.environ.get("this")
|
12 |
-
response = ai.Completion.create(
|
13 |
-
engine="text-davinci-003",
|
14 |
-
prompt=prompt,
|
15 |
-
temperature=0,
|
16 |
-
max_tokens=2000,
|
17 |
-
top_p=1,
|
18 |
-
frequency_penalty=0,
|
19 |
-
presence_penalty=0)
|
20 |
-
response = response['choices'][0]['text']
|
21 |
-
response = response.strip()
|
22 |
-
# response = "\n",response,"\n"
|
23 |
-
return response
|
24 |
-
|
25 |
-
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
26 |
-
iface.launch()
|
27 |
-
|
28 |
-
# import requests
|
29 |
-
# import json
|
30 |
-
# import os
|
31 |
# import gradio as gr
|
|
|
|
|
|
|
32 |
|
33 |
-
#
|
34 |
-
|
35 |
-
# def main(prompt):
|
36 |
# if "created you" in prompt or "made you" in prompt or "developed you" in prompt:
|
37 |
# response = "I was created by Dawn Saju, Alwin Mathew, Sivai Bala, Bryan Godwin and Mohammed Zaim"
|
38 |
# return response
|
39 |
# else:
|
40 |
-
#
|
41 |
-
#
|
42 |
-
# "
|
43 |
-
#
|
44 |
-
#
|
45 |
-
#
|
46 |
-
#
|
47 |
-
#
|
48 |
-
#
|
49 |
-
#
|
50 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# import gradio as gr
|
2 |
+
# import openai as ai
|
3 |
+
# import os
|
4 |
+
# import requests
|
5 |
|
6 |
+
# def greet(prompt):
|
|
|
|
|
7 |
# if "created you" in prompt or "made you" in prompt or "developed you" in prompt:
|
8 |
# response = "I was created by Dawn Saju, Alwin Mathew, Sivai Bala, Bryan Godwin and Mohammed Zaim"
|
9 |
# return response
|
10 |
# else:
|
11 |
+
# ai.api_key = os.environ.get("this")
|
12 |
+
# response = ai.Completion.create(
|
13 |
+
# engine="text-davinci-003",
|
14 |
+
# prompt=prompt,
|
15 |
+
# temperature=0,
|
16 |
+
# max_tokens=2000,
|
17 |
+
# top_p=1,
|
18 |
+
# frequency_penalty=0,
|
19 |
+
# presence_penalty=0)
|
20 |
+
# response = response['choices'][0]['text']
|
21 |
+
# response = response.strip()
|
22 |
+
# # response = "\n",response,"\n"
|
23 |
+
# return response
|
24 |
+
|
25 |
+
# iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
26 |
+
# iface.launch()
|
27 |
+
|
28 |
+
import requests
|
29 |
+
import json
|
30 |
+
import os
|
31 |
+
import gradio as gr
|
32 |
+
|
33 |
+
url = "https://api.writesonic.com/v2/business/content/chatsonic?engine=premium"
|
34 |
+
|
35 |
+
def main(prompt):
|
36 |
+
if "created you" in prompt or "made you" in prompt or "developed you" in prompt:
|
37 |
+
response = "I was created by Dawn Saju, Alwin Mathew, Sivai Bala, Bryan Godwin and Mohammed Zaim"
|
38 |
+
return response
|
39 |
+
else:
|
40 |
+
payload = {
|
41 |
+
"enable_google_results": True,
|
42 |
+
"enable_memory": False,
|
43 |
+
"history_data": [{"name": "Dawn"}],
|
44 |
+
"input_text": prompt
|
45 |
+
}
|
46 |
+
headers = {
|
47 |
+
"accept": "application/json",
|
48 |
+
"content-type": "application/json",
|
49 |
+
"X-API-KEY": os.environ.get("test")
|
50 |
+
}
|
51 |
|
52 |
+
try:
|
53 |
+
response = requests.post(url, json=payload, headers=headers)
|
54 |
+
data = json.loads(response.text)
|
55 |
+
try:
|
56 |
+
data = data["message"]
|
57 |
+
if "ChatSonic" in data:
|
58 |
+
data = data.replace("ChatSonic","John")
|
59 |
+
return data
|
60 |
+
except Exception as e:
|
61 |
+
return "Error occured!"
|
62 |
+
except Exception as e:
|
63 |
+
return e.message
|
64 |
|
65 |
+
iface = gr.Interface(fn=main, inputs="text", outputs="text")
|
66 |
+
iface.launch()
|