File size: 2,807 Bytes
5498319
363c200
5498319
 
 
363c200
5498319
 
e32ce7d
 
 
 
 
 
5498319
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09a2703
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
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", messages=messages
        )
        reply = chat.choices[0].message.content
        messages.append({"role": "assistant", "content": reply})
        return reply

def clear():
    return None, None

#inputss = gr.inputs.Textbox(lines=7, label="Porozmawiaj z naszym chatbotem trioGPT, virtualnym ekspertem rynku nieruchomości")
#outputss = gr.outputs.Textbox(label="Odpowiedź")

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")#, elem_classes="textbox")
	outputs = gr.Textbox(label="Odpowiedź", elem_id="outputs")#, elem_classes="textbox")	
	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()