File size: 4,563 Bytes
fb48099
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57c13cd
825e58e
fb48099
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c89ce8
 
 
9fe1a83
0c89ce8
 
9fe1a83
0c89ce8
 
d85fd16
0c89ce8
 
 
9fe1a83
0c89ce8
 
9fe1a83
0c89ce8
 
fb48099
0c89ce8
fb48099
 
 
 
7569d93
 
fb48099
 
825e58e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d90f29f
825e58e
 
 
 
 
 
 
 
 
 
 
 
8563604
825e58e
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# import gradio as gr
# import openai as ai
# import os
# import requests

# def greet(prompt):
#     if "created you" in prompt or "made you" in prompt or "developed you" in prompt:
#         response = "I was created by Dawn Saju, Alwin Mathew, Sivai Bala, Bryan Godwin and Mohammed Zaim"
#         return response
#     else:
#         ai.api_key = os.environ.get("test")
#         response = ai.Completion.create(
#             engine="text-davinci-003",
#             prompt=prompt,
#             temperature=0,
#             max_tokens=2000,
#             top_p=1,
#             frequency_penalty=0,
#             presence_penalty=0)
#         response = response['choices'][0]['text']
#         response = response.strip()
#         # response = "\n",response,"\n"
#         return response

# iface = gr.Interface(fn=greet, inputs="text", outputs="text")
# iface.launch()

from revChatGPT.Official import Chatbot
import gradio as gr
import os

def main(user):
    # def get_input(prompt):
    #     """
    #     Multi-line input function
    #     """
    #     # Display the prompt
    #     print(prompt, end="")

    #     # Initialize an empty list to store the input lines
    #     lines = []

    #     # Read lines of input until the user enters an empty line
    #     while True:
    #         line = input()
    #         if line == "":
    #             break
    #         lines.append(line)

    #     # Join the lines, separated by newlines, and store the result
    #     user_input = "\n".join(lines)

    #     # Return the input
    #     return user_input

    # def chatbot_commands(cmd: str) -> bool:
    #     """
    #     Handle chatbot commands
    #     """
    #     if cmd == "!help":
    #         print(
    #             """
    #         !help - Display this message
    #         !rollback - Rollback chat history
    #         !reset - Reset chat history
    #         !exit - Quit chat
    #         """
    #         )
    #     elif cmd == "!exit":
    #         exit()
    #     elif cmd == "!rollback":
    #         chatbot.rollback(1)
    #     elif cmd == "!reset":
    #         chatbot.reset()
    #     else:
    #         return False
    #     return True
    # Initialize chatbot
    chatbot = Chatbot(api_key=os.environ.get("test2"))
    # Start chat
    def get_input(var1):
        # Display the prompt
        print(user, end="")
        
        # Initialize an empty list to store the input lines
        lines = []
        
        # Read lines of input until the user enters an empty line
        while True:
            line = ""
            if line == "":
                break
            lines.append(line)
        
        # Join the lines, separated by newlines, and store the result
        user_input = "\n".join(lines)
        
        # Return the input
        return user_input
    while True:
        PROMPT = get_input("\nUser:\n")
        # if PROMPT.startswith("!"):
        #     if chatbot_commands(PROMPT):
        #         continue
        response = chatbot.ask(PROMPT)
        response = "John: " + response["choices"][0]["text"]
        return response

iface = gr.Interface(fn=main, inputs="text", outputs="text")
iface.launch()

# import requests
# import json
# import os
# import gradio as gr

# url = "https://api.writesonic.com/v2/business/content/chatsonic?engine=premium"

# def main(prompt):
#     if "created you" in prompt or "made you" in prompt or "developed you" in prompt:
#         response = "I was created by Dawn Saju, Alwin Mathew, Sivai Bala, Bryan Godwin and Mohammed Zaim"
#         return response
#     else:
#         payload = {
#             "enable_google_results": True,
#             "enable_memory": False,
#             "history_data": [{"name": "Dawn"}],
#             "input_text": prompt
#         }
#         headers = {
#             "accept": "application/json",
#             "content-type": "application/json",
#             "X-API-KEY": os.environ.get("test")
#         }

#         try:
#             response = requests.post(url, json=payload, headers=headers)
#             data = json.loads(response.text)
#             try:
#                 data = data["message"]
#                 if "ChatSonic" in data:
#                     data = data.replace("ChatSonic","John")
#                     return data
#             except Exception as e:
#                 return "Error occured!"
#         except Exception as e:
#             return e.message

# iface = gr.Interface(fn=main, inputs="text", outputs="text")
# iface.launch()