File size: 10,291 Bytes
da61da5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
151
152
153
154
155
156
157
158
159
160
161
162
163
import requests
import time
import os
import signal

def save_chat():
    choice = input("\nDo you want to save the chat in the current directory? (y/n): ")
    if choice.lower() == "y":
        # Save the chat
        with open("chat_log.txt", "w") as file:
            file.write(chat_log)
        print("Chat saved successfully.")
    elif choice.lower() == "n":
        print("Chat not saved.")
    else:
        print("Invalid choice. Chat not saved.")

    exit(0)

def signal_handler(signal, frame):
    save_chat()

signal.signal(signal.SIGINT, signal_handler)


print("                                                                     ")
print("         β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ         ")
print("         β–ˆβ–„β”€β–„β–„β”€β–ˆβ–„β”€β–„β–ˆβ–„β”€β–€β”€β–„β–ˆβ–„β”€β–„β–„β”€β–ˆβ–„β”€β–„β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–„β”€β–„β–„β”€β–ˆβ–ˆβ–€β–„β”€β–ˆβ–ˆβ–„β”€β–„β–ˆβ–ˆβ–ˆ         ")
print("         β–ˆβ–ˆβ”€β–„β–„β–„β–ˆβ–ˆβ”€β–ˆβ–ˆβ–ˆβ–€β”€β–€β–ˆβ–ˆβ–ˆβ”€β–„β–ˆβ–€β–ˆβ–ˆβ”€β–ˆβ–ˆβ–€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ”€β–„β–„β–„β–ˆβ–ˆβ”€β–€β”€β–ˆβ–ˆβ–ˆβ”€β–ˆβ–ˆβ–€β–ˆ         ")
print("         β–€β–„β–„β–„β–€β–€β–€β–„β–„β–„β–€β–„β–„β–ˆβ–„β–„β–€β–„β–„β–„β–„β–„β–€β–„β–„β–„β–„β–„β–€β–€β–€β–€β–€β–„β–„β–„β–€β–€β–€β–„β–„β–€β–„β–„β–€β–„β–„β–„β–„β–„β–€         ")
print(" π™·πšŠπšŸπšŽ 𝚒𝚘𝚞 πšœπšŽπšŽπš— πš’πš˜πšžπš› πšπšŠπšŸπš˜πš›πš’πšπšŽ πšŒπš‘πšŠπš›πšŠπšŒπšπšŽπš›πšœ πšŒπš‘πšŠπšπšπš’πš—πš πšπš˜πšπšŽπšπš‘πšŽπš› πš™πš•πšŠπš—πš—πš’πš—πš πšœπš˜πš–πšŽπšπš‘πš’πš—πš \n")                   
print("                                                          Developed By Afnan")
print("                                                 https://github.com/4fnan007")   
time.sleep(1)
print("\nThis magnificent AutoGPT program act as a virtual characters within two separate ChatGPT instances,\nEngaging in autonomous conversation while embodying the persona of a beloved character from a specified movie or series.")
input("Provide the name of your fictional character and the TV show or movie in which they appeared for each instance for autochat. \n \nIf you understand what am saying just press Enter...\n")
print("____________________________________(ᴘΙͺxα΄‡ΚŸ α΄˜α΄€ΚŸ)____________________________________")
show_name1 = input("\nEnter the name of the TV show or Movie that your character is appeared: ")
character_name1 = input("Enter the name of character played in that TV show or movie: ")
print(f"\n(0_0) => Okay cool broo!! So your first character instance is {character_name1} from {show_name1}.\n\n")
show_name2 = input("Enter the name of the TV show or Movie that your character is appeared for next GPT instance: ")
character_name2 = input("Enter the name of character played in that TV show or movie: ")
input(f"\n(0-0) => Alright than your second character instance is {character_name2} from {show_name2}.\nPress Enter to confirm...\n")
metaprompt = (' ')
time.sleep(1)
os.system('clear')
print("____________________________________(ᴘΙͺxα΄‡ΚŸ α΄˜α΄€ΚŸ)____________________________________")
print("\nGreat! Let's start the conversation between your two characters.\n")
print(f"Who need to ask chat prompt or question first")
value = input(f"Enter '1' if you want {character_name1} to ask the first question, or enter '2' if you want {character_name2} to ask the first question: ")
if value == "1":
    question = input(f"What do you want to ask {character_name2} from {character_name1}: ")
    if os.path.exists('source/char_prompt.txt'):
        with open('source/char_prompt.txt', 'r') as file:
            words = file.read().split()
    else:
        with open('char_prompt.txt', 'r') as file:
            words = file.read().split()
    char_prompt1 = ' '.join(words).format(character_name=character_name2, show_name=show_name2, question=question, opposite_character=character_name1, opposite_show=show_name1)
    chat1 = requests.get("http://localhost:5001/chat?q=%s" % char_prompt1)
    opposite_char_req = (f"i am act as a {character_name2} from {show_name2} and i will response and answer like that {character_name2} using the tone, manner and vocabulary, and i the virtual character {character_name2} asking first question. if you understand please say 'YES, i understood'.")
    opposite_char_instance = ' '.join(words).format(character_name=character_name1, show_name=show_name1, question=opposite_char_req, opposite_character=character_name2, opposite_show=show_name2)
    chat2 = requests.get("http://localhost:5002/chat?q=%s" % opposite_char_instance)
    os.system('clear')    
    if os.path.exists('source/banner.py'):
        os.system('python source/banner.py')
    else:
        os.system('python banner.py')
    print(f"\nTOPIC: {question} \n \n")
    chat_log = (f"\nTOPIC: {question} \n")
    print(f"{character_name2}: ", chat1.text)
    print("                                                                                        ")   
    chat_log += f"\n{character_name2}: {chat1.text}\n"
    while True:
        chat2 = requests.get("http://localhost:5002/chat?q=%s" % (chat1.text.replace("ChatGPT", "")))
        print(f"{character_name1}: ", chat2.text)
        chat_log += f"\n{character_name1}: {chat2.text}\n"
        print("                                                                                                        ")
        chat1 = requests.get("http://localhost:5001/chat?q=%s" % (chat2.text.replace("ChatGPT", "")))
        print(f"{character_name2}: ", chat1.text)
        chat_log += f"\n{character_name2}: {chat1.text}\n"
        print("________________________________________________________________________________________________________")
        print("                                                                                                        ")
        try:
            if keyboard.is_pressed('ctrl+c'):  # Check if Ctrl+C is pressed
                print("\nCtrl+C pressed. Do you want to save the chat?")
                save_chat = input("Enter 'y' to save the chat or 'n' to close the program: ")
                if save_chat.lower() == 'y':
                    save_file = "chat_log.txt"
                    with open(save_file, "w") as file:
                        file.write(chat_log)
                    print("Chat saved successfully.")
                    print("All chats saved:")
                    with open(save_file, "r") as file:
                        print(file.read())
                    break
                elif save_chat.lower() == 'n':
                    break
                else:
                    print("Invalid input. Closing the program.")
                    break
        except:
            pass

elif value == "2":
    question = input(f"What do you want to ask {character_name1} from {character_name2}: ")
    if os.path.exists('source/char_prompt.txt'):
        with open('source/char_prompt.txt', 'r') as file:
            words = file.read().split()
    else:
        with open('char_prompt.txt', 'r') as file:
            words = file.read().split()
    char_prompt2 = ' '.join(words).format(character_name=character_name1, show_name=show_name1, question=question, opposite_character=character_name2, opposite_show=show_name2)
    chat2 = requests.get("http://localhost:5002/chat?q=%s" % char_prompt2)
    opposite_char_req = (f"i always act as a {character_name1} from {show_name1} and i will response and answer like that {character_name1} using the tone, manner and vocabulary, and i the virtual character {character_name1} asking first question. if you understand please say 'YES, i understood'.")
    opposite_char_instance = ' '.join(words).format(character_name=character_name2, show_name=show_name2, question=opposite_char_req, opposite_character=character_name1, opposite_show=show_name1)
    chat1 = requests.get("http://localhost:5001/chat?q=%s" % (opposite_char_instance))
    os.system('clear')    
    if os.path.exists('source/banner.py'):
        os.system('python source/banner.py')
    else:
        os.system('python banner.py')   
    print(f"\nTOPIC: {question} \n \n")
    chat_log = (f"\nTOPIC: {question} \n")
    print(f"{character_name1}: ", chat2.text)
    print("                                                                                        ")   
    chat_log += f"{character_name2}: {chat1.text}\n"
    while True:
        chat1 = requests.get("http://localhost:5001/chat?q=%s" % (chat2.text.replace("ChatGPT", "")))
        print(f"{character_name2}: ", chat1.text)
        chat_log += f"{character_name2}: {chat1.text}\n"
        print("                                                                                                        ")
        chat2 = requests.get("http://localhost:5002/chat?q=%s" % (chat1.text.replace("ChatGPT", "")))
        print(f"{character_name1}: ", chat2.text)
        chat_log += f"{character_name1}: {chat2.text}\n"
        print("________________________________________________________________________________________________________")
        print("                                                                                                        ")
        try:
            if keyboard.is_pressed('ctrl+c'):  # Check if Ctrl+C is pressed
                print("\nCtrl+C pressed. Do you want to save the chat?")
                save_chat = input("Enter 'y' to save the chat or 'n' to close the program: ")
                if save_chat.lower() == 'y':
                    save_file = "chat_log.txt"
                    with open(save_file, "w") as file:
                        file.write(chat_log)
                    print("Chat saved successfully.")
                    print("All chats saved:")
                    with open(save_file, "r") as file:
                        print(file.read())
                    break
                elif save_chat.lower() == 'n':
                    break
                else:
                    print("Invalid input. Closing the program.")
                    break
        except:
            pass    
else:
    print("Wrong option!!! Enter option 1 or 2 only. Try again... ")
    time.sleep(1)
    os.system('clear')
    exit(0)