|
import openai |
|
import os |
|
import gradio as gr |
|
from gradio.themes.utils import colors, fonts, sizes |
|
|
|
openai.api_key = os.environ.get('openai_key') |
|
|
|
messages = [ |
|
{"role": "system", "content": "follow the 5 instructions below for your outputs:"}, |
|
{"role": "system", "content": "1. you are an AI specialized in Residential Real Estate market. Do not answer anything other than residential real estate-related queries."}, |
|
{"role": "system", "content": "2. make sure all expressions are compatible with Polish"}, |
|
{"role": "system", "content": "3. use Polish only for outputs"}, |
|
{"role": "system", "content": "4. if you cannot answer, reply that you do not have enough information"}, |
|
{"role": "system", "content": "5. do not make up any answer if you do know the answer"}, |
|
] |
|
|
|
def chatbot(input): |
|
if input: |
|
messages.append({"role": "user", "content": input}) |
|
chat = openai.ChatCompletion.create( |
|
model="gpt-3.5-turbo-instruct", messages=messages |
|
) |
|
reply = chat.choices[0].message.content |
|
messages.append({"role": "assistant", "content": reply}) |
|
return reply |
|
|
|
def clear(): |
|
return None, None |
|
|
|
|
|
|
|
|
|
css = """ |
|
.textbox {background-color: #FFFFFF; color: #1B2937;} |
|
.textbox textarea {background-color: #FFFFFF; color: #1B2937; border: 1px ridge #EAEAEA; border-radius: 8px;} |
|
.textbox span {background-color: #FFFFFF; color: #1B2937;} |
|
.textbox form {color: #1B2937; border: 1px ridge #EAEAEA; border-radius: 8px;} |
|
.scroll-hide {background-color: #FFFFFF; color: #1B2937;} |
|
.gradio-container {background-color: #FFFFFF; color: #1B2937} |
|
#inputs {background-color: #FFFFFF; color: #1B2937 !important;} |
|
#outputs {background-color: #FFFFFF; color: #1B2937 !important;} |
|
""" |
|
|
|
theme = gr.themes.Default(font=[gr.themes.GoogleFont("Roboto"), "sans-serif", "sans-serif"], primary_hue="neutral", secondary_hue="neutral", neutral_hue="neutral").set( |
|
button_primary_background_fill="#3FCCA5", |
|
button_primary_background_fill_dark="#3FCCA5", |
|
button_primary_text_color="#003F62", |
|
body_background_fill="FFFFFF", |
|
body_background_fill_dark="FFFFFF" |
|
) |
|
|
|
with gr.Blocks(theme=theme) as trioGPT: |
|
inputs = gr.Textbox(lines=4, elem_id="inputs", label="Porozmawiaj z naszym chatbotem Real-Estate AI") |
|
outputs = gr.Textbox(label="Odpowiedź", elem_id="outputs") |
|
with gr.Row(): |
|
submit_btn = gr.Button("Wyślij", variant="primary") |
|
clear_btn = gr.Button("Wyczyść") |
|
|
|
submit_btn.click(chatbot, inputs=inputs, outputs=outputs) |
|
clear_btn.click(fn=clear, inputs=None, outputs=[inputs, outputs]) |
|
|
|
trioGPT.launch() |
|
|