Spaces:
Sleeping
Sleeping
#import openai | |
import gradio as gr | |
#openai.api_key = "####" | |
""" | |
messages = [{"role": "system", "content": "You are a financial experts that specializes in real estate investment and negotiation"}] | |
def CustomChatGPT(user_input): | |
messages.append({"role": "user", "content": user_input}) | |
response = openai.ChatCompletion.create( | |
model = "gpt-3.5-turbo", | |
messages = messages | |
) | |
ChatGPT_reply = response["choices"][0]["message"]["content"] | |
messages.append({"role": "assistant", "content": ChatGPT_reply}) | |
return ChatGPT_reply | |
""" | |
answers = [] | |
""" | |
def picabot(user_input): | |
answers.append(user_input) | |
# take user input, remove all spaces, make it lower case | |
user_input = user_input.replace(" ", "").lower() | |
if user_input in ["lod", "loď"]: | |
return "Choď do piči." | |
else: | |
return "Povedz lod " | |
demo = gr.Interface(fn=picabot, | |
inputs = gr.Textbox(lines=1, placeholder="Takže... ?"), | |
outputs = "text", | |
title = "Pičabot", | |
description = "Pičabot je chatbot, ktorý vám pomôže v každodennom živote.") | |
demo.launch(share=False) # True for sharing of url: does not work on my DTI PC due to security | |
print(answers) | |
""" | |
import time | |
def picabot(message, history): | |
""" | |
message: str, user input | |
history: list of lists, history of user inputs and chatbot responses | |
""" | |
if len(history) == 10: | |
chatbot_reply = "Too many messages, leave now please." | |
# take user input, remove all spaces, make it lower case | |
message = message.lower() | |
# remove all diacritics from the message | |
message = message.replace("á", "a").replace("ä", "a").replace("č", "c").replace("ď", "d").replace("é", "e").replace("í", "i").replace("ĺ", "l").replace("ľ", "l").replace("ň", "n").replace("ó", "o").replace("ô", "o").replace("ŕ", "r").replace("š", "s").replace("ť", "t").replace("ú", "u").replace("ý", "y").replace("ž", "z") | |
if any(word in message for word in ["lod", "loď"]): | |
chatbot_reply = "Choď do piči." | |
elif any(word in message for word in ["ahoj", "čau", "čaues", "cauko"]): | |
chatbot_reply = "Ahoj." | |
elif any(word in message for word in ["rada", "radka", "radoslava", "radar"]): | |
chatbot_reply = "Čoje ?????." | |
elif any(word in message for word in ["pica", "piča", "kokot", "kunda", "kurva", "pici", "pice", "piči", "pice", "jebat"]): | |
chatbot_reply = "Nenadávaj mi tu boha." | |
else: | |
chatbot_reply = "Povedz loď." | |
# wait 1/2 second before replying | |
time.sleep(0.5) | |
return chatbot_reply | |
demo = gr.ChatInterface( | |
picabot, | |
chatbot=gr.Chatbot(height=400), | |
textbox=gr.Textbox(placeholder="Čauko kakauko.", container=False, scale=7), | |
title="Pičabot", | |
description="This is your best friend now", | |
theme="soft", | |
# examples buttons, maybe for later | |
#examples=["Hello", "Am I cool?", "Are tomatoes vegetables?"], | |
#cache_examples=True, | |
retry_btn=None, | |
undo_btn="Undo", | |
clear_btn="Clear chat", | |
) | |
demo.launch(share=False) # True for sharing of url: does not work on my PC nor HuggingFace |