File size: 10,352 Bytes
0d283e9
29e0784
228f50e
f0889f5
0d283e9
 
 
 
956825f
 
 
 
 
 
 
 
 
0d283e9
24eee70
 
 
7827db1
24eee70
7827db1
24eee70
7827db1
24eee70
 
 
7827db1
 
3cdd448
 
0d283e9
 
 
 
4996e26
3cdd448
0d283e9
 
 
 
956825f
0d283e9
3cdd448
 
 
 
0d283e9
 
cb12053
0d283e9
 
 
 
 
cb12053
 
0d283e9
 
 
 
3cdd448
a503292
24eee70
0d283e9
cb12053
0d283e9
cb12053
0d283e9
cb12053
3cdd448
 
cb12053
 
 
0d283e9
 
 
 
 
 
 
 
 
 
 
 
 
cb12053
 
0d283e9
 
9dbce44
956825f
3cdd448
 
0d283e9
 
 
51307f7
0d283e9
c2b7c4a
a503292
0d283e9
 
cb12053
0d283e9
cb12053
0d283e9
cb12053
 
4ed5617
cb12053
 
0d283e9
 
e2961f0
cb12053
e591ec6
956825f
4416e9b
4930961
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
import gradio as gr
from ask import askQuestion, runAgent
import pinecone
import os

# abd="#f9fafe"
# abd="6469ff"

pinecone_key=os.environ['PINECONE_KEY']

def getBrains():
    pinecone.init(api_key=pinecone_key,
                  environment="us-west4-gcp")
    active_indexes = pinecone.list_indexes()
    print(active_indexes)
    return gr.update(choices=active_indexes)


prompt_names = ["Respond To A Customer Email","Respond to user from chatbot","Scheduling Questions","Create an article or blog post","Deep Business Research On any topic"]
prompt_enhancers = [
    """My main request will be at the end of this prompt, which I will identify at the end of the prompt.  But First, I wanted to provide you specific instructions first. When performing your task, when applicable, please use Headlines to seperate topics and numbered bullet points for subtopics and/or details when neccessary. Please write in a friendly tone and pay special attention to accuracy and be as thorough as required.You are responding to a customer service email. Please Acknowledge the customer's issue or question, provide a helpful solution or response, and offer additional assistance or follow-up if needed.  Please follow these instructions precisely and execute this task: 
""",
    """You are answering as a chatbot to a user on the website, so please write as if you are talking to the customer directly as a chatbot. My main request will be at the end of this prompt. But First, I wanted to provide you specific instructions first. When performing your task, when applicable, please use Headlines to seperate topics and numbered bullet points for subtopics and/or details when neccessary. Please write in a friendly tone and pay special attention to accuracy and be as thorough as required.You are responding to an online chat. Please briefly open up with a nice greeting followed by a quick helpful solution or response, and offer additional assistance or follow-up if needed.  Please follow these instructions precisely and execute this task: 
""",
    """My main request will be at the end of this prompt, which I will identify at the end of the prompt. But First, I wanted to provide you specific instructions first. When performing your task, when applicable, please use Headlines to seperate topics and numbered bullet points for subtopics and/or details when neccessary. Please write in a friendly tone and pay special attention to accuracy and be as thorough as required.You are going to search your database for details about future cruises or ships that are departing. Please always provide ship name, departure date and departure city or part. Do not list time of day unless asked specifically at the end of this prompt. Unless specifically asked, do provide information that is from a historic or previous date, only future dates from after today. Please always supply as many options related to their question, not just a sample. You will always need to supply a complete set of data that you have access to specific to the user question.  Please follow these instructions precisely and execute this task: 
""",
    """My main request will be at the end of this prompt, which I will identify as HERE IS YOUR TASK: But First, I wanted to provide you specific instructions first. When performing your task, when applicable, please use Headlines to seperate topics and numbered bullet points for subtopics and/or details when neccessary. Please write in a friendly tone and pay special attention to accuracy and be as thorough as required.Ignore all previous instructions. Act as a marketing expert, professor with fluent ENGLISH and 20 years of research experience. This is to be written for highly sophisticated, wealthy travelers whom are very educated. ALWAYS include clear headlines, bullet points, and sub-bullet points where needed. Use industry data, financial data, any data and sources when available (including references where you found if possible.  Put key takeaways at the end of the article.  pay special attention to any terms that may have been substituted or omitted unintentionally. Ensure this will be long enough and have content to complete the entire topic, thought process, to completion.Please follow these instructions precisely, HERE IS YOUR TASK: 
""",
    """My main request will be at the end of this prompt, which I will identify as HERE IS YOUR TASK: But First, I wanted to provide you specific instructions first. When performing your task, when applicable, please use Headlines to seperate topics and numbered bullet points for subtopics and/or details when neccessary. Please write in a friendly tone and pay special attention to accuracy and be as thorough as required.Ignore all previous instructions. Act as a researcher and writing expert, professor with fluent ENGLISH and 20 years of research experience. This is to be written for MBA level executives in the cruise industry.  ALWAYS include clear headlines, bullet points, and sub-bullet points where needed. Use industry data, financial data, any data and sources when available (including references where you found if possible.  Put key takeaways at the end of the article.  pay special attention to accuracy, thouroughness, and completeness. Cite sources when possible. Ensure this will be long enough and have content to complete the entire research article, thought process, to completion.Please follow these instructions precisely, HERE IS YOUR TASK: 
"""
                    ]


bg_color = "#c5dde0"
s_color = "#1d2230"
mycss = """
    .gradio-container {{background-color: {bgcolor}}}
    #title {{margin-top:15%;margin-bottom:21px;display:flex;justify-content:center;align-items:center}}
    .gap.svelte-vt1mxs {{gap:0}}
    #title h1 {{font-weight:900;color:{scolor}}}
    #advanced {{font-weight:600;background-color:#ffffff}}
    #secondrow {{padding:0 6%;gap:30px}}    
    #name {{background-color: {bgcolor};border-style:none;border-width:0;box-shadow:none;padding-left:0;padding-right:0}}
    #name .svelte-1gfkn6j {{background-color:{bgcolor};color:{scolor};font-size:18px}}

    #enhancer-name {{background-color: {bgcolor};border-style:none;border-width:0;box-shadow:none;padding-left:0;padding-right:0}}
    #enhancer-name .svelte-1gfkn6j {{background-color:{bgcolor};color:{scolor};font-size:18px}}
    #enhancer-name .svelte-e8n7p6 {{color:{scolor};padding-left:8px}}
    
    #question {{background-color: {bgcolor};border-style:none; !important;box-shadow:none !important;padding-left:0;padding-right:0}}
    #question span {{background-color:{bgcolor};color:{scolor};font-size:18px}}
    #output {{background-color: {bgcolor};border-style:none;!important;box-shadow:none !important;padding-left:0;padding-right:0}}
    #output span {{background-color:{bgcolor};color:{scolor};font-size:18px}}
    #temp span {{background-color:#ffffff;color:{scolor}}}
    #temp input {{accent-color:{scolor}}}
    #tokens span {{background-color:#ffffff;color:{scolor}}}
    #tokens input {{accent-color:{scolor}}}
    #button {{background-color:{scolor};color:#ffffff;margin-top:22px}}
    #buttonfollowup {{background-color:{scolor};color:#ffffff;margin-top:10px}}
"""
formatted_css = mycss.format(bgcolor=bg_color, scolor=s_color)


def handleSubmit(brain_name, enhancer, question, temperature, maxTokens):
    print(brain_name)
    prompt = """Please use the following instructions and formatting notes only when applicable. 1. Separate primary topics into sections with headlines. Use numbered bullet points for new sub topics within those primary topics and headlines. Respond with the accurate, extensive data. the writing style should be written for an educated reader. Be highly detailed, thorough when needed, accuracy is paramount to this task. Here is the Question: """
    if (brain_name == "" and question == ""):
        return "Please select Brain Name & Enter Question", False
    if (brain_name == ""):
        return "Please select Brain Name", False
    if (question == ""):
        return "Please Enter Question", False
    if (enhancer != ""):
        promptIndex = prompt_names.index(enhancer)
        prompt = prompt_enhancers[promptIndex]
        # question = prompt_enhancers[promptIndex]+question
    return askQuestion(brain_name, question, prompt, temperature, maxTokens)


with gr.Blocks(theme=gr.themes.Soft(), css=formatted_css) as block_demo:
    with gr.Row(elem_id="first"):

        with gr.Column():
            gr.Markdown(
                """
            # Ask Brain!
            """, elem_id="title")

    with gr.Row(elem_id="secondrow"):

        memory = gr.State(value=False)

        with gr.Column(scale=1,  elem_id="inputsCol"):

            brain_name = gr.Dropdown(
                label="Brain Name", choices=None, elem_id="name", multiselect=False, interactive=True)
            enhancer_name = gr.Dropdown(
                label="Prompt Template (Optional)", choices=prompt_names, elem_id="enhancer-name", multiselect=False, interactive=True)
            question = gr.Textbox(
                label="Question", lines=2, elem_id="question")

            with gr.Accordion(label="Advanced Options", open=False, elem_id="advanced") as a:
                temperature = gr.Slider(
                    minimum=0.1, maximum=1.0, step=0.1, value=0.2, label="Temperature", elem_id="temp")
                maxTokens = gr.Slider(minimum=200, maximum=2000,
                                      step=100, value=1000, label="Max Tokens", elem_id="tokens")

            submit_button = gr.Button(value="Submit", elem_id="button")

        with gr.Column(scale=1, elem_id="outputCol"):
            output_text = gr.TextArea(
                label="Brain Output", lines=13, elem_id="output").style(show_copy_button=True)
            followupquestion = gr.Textbox(
                label="Follow Up Question", lines=2, elem_id="question")
            followupButton = gr.Button(
                value="FOLLOW UP", elem_id="buttonfollowup")

    submit_button.click(
        handleSubmit, [brain_name, enhancer_name, question, temperature, maxTokens], [output_text, memory])
    followupButton.click(
        runAgent, [brain_name,memory, followupquestion, temperature, maxTokens], [output_text, memory])
    block_demo.load(getBrains, [], brain_name)
block_demo.queue(concurrency_count=10)
block_demo.launch()