# 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() |