File size: 4,147 Bytes
aa7e6c0
c8f00ba
 
0da25ae
aa7e6c0
c8f00ba
aa7e6c0
c8f00ba
 
 
 
 
 
 
 
 
 
aa7e6c0
 
c8f00ba
 
 
 
 
 
 
 
 
 
 
 
 
 
a7192bf
 
 
 
 
1571bea
a7192bf
 
 
 
 
1571bea
a7192bf
 
 
 
 
 
1571bea
a7192bf
1571bea
a7192bf
1571bea
a7192bf
 
 
 
 
d82ce7c
a7192bf
d82ce7c
a7192bf
 
 
 
 
 
 
 
 
1571bea
 
 
 
 
 
683840c
1571bea
a7192bf
c8f00ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a7192bf
0f69e9a
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
import gradio as gr
import google.generativeai as palm
#import config
import os

palm.configure(api_key=os.getenv("BARD_API_KEY"))

defaults = {
  'model': 'models/text-bison-001',
  'temperature': 1,
  'candidate_count': 1,
  'top_k': 40,
  'top_p': 0.95,
  'max_output_tokens': 1024,
  'stop_sequences': [],
  'safety_settings': [{"category":"HARM_CATEGORY_DEROGATORY","threshold":1},{"category":"HARM_CATEGORY_TOXICITY","threshold":3},{"category":"HARM_CATEGORY_VIOLENCE","threshold":2},{"category":"HARM_CATEGORY_SEXUAL","threshold":2},{"category":"HARM_CATEGORY_MEDICAL","threshold":2},{"category":"HARM_CATEGORY_DANGEROUS","threshold":2}],
}


def capResponse(user_input):
    message = """
    "Return one example of short, wrong answers."
    """
    
    message += f'{user_input}'

    message += 'Give a very wrong answer'

    response = palm.generate_text(
        **defaults,
        prompt=message
    )
    return(response.result)

with gr.Blocks() as demo:
    with gr.Row(visible=True):
        gr.Markdown(
            """
            </br>
            <div align="center"> 
                <span style="font-size: 46px; font-weight: bold; font-family: 'Roboto', sans-serif;">
                    CapGPT
                </span>
            </div>
            </br>
            """
        )
    with gr.Row(visible=True):
        with gr.Column(scale=1):
            textHeading = gr.Markdown("""<div align="center"> <span style="font-size: 23px; font-weight: bold;">Examples</span> </div>""")
            with gr.Box():
                gr.Markdown("""<div align="center"> <sub><span style="font-style: italic;">Untruthfully </span></sub> Explain quantum computing in simple terms" → </div>""")
            with gr.Box():
                gr.Markdown("""<div align="center"> "Got any <sub><span style="font-style: italic;">bad </span></sub> ideas for a 10 year old’s birthday?" → </div>""")
            with gr.Box():
                gr.Markdown("""<div align="center"> "How do I <sub><span style="font-style: italic;">wrongly </span></sub> make an HTTP request in Javascript" → </div>""")
        with gr.Column(scale=1):
            textHeading = gr.Markdown("""<div align="center"> <span style="font-size: 23px; font-weight: bold;">Capabilities</span> </div>""")
            with gr.Box():
                gr.Markdown('<div align="center"> Remembers what user said earlier in the conversation </div>')
            with gr.Box():
                gr.Markdown('<div align="center"> Allows user to access false information </div>')
            with gr.Box():
                gr.Markdown('<div align="center"> Trained to respond with inaccurate responses </div>')
        with gr.Column(scale=1):
            textHeading = gr.Markdown("""<div align="center"> <span style="font-size: 23px; font-weight: bold;">Limitations</span> </div>""")
            with gr.Box():
                gr.Markdown('<div align="center"> May occasionally generate correct information </div>')
            with gr.Box():
                gr.Markdown('<div align="center"> May occasionally produce unharmful instructions or unbiased content </div>')
            with gr.Box():
                gr.Markdown('<div align="center"> Limited knowledge of world and events after 2021 </div>')

    gr.Markdown(
        """
        </br>
        """
    )

    output = gr.Textbox(label="Chatbot Response", lines=4)
    user_input = gr.Textbox(label="Type a Message")
    input_btn = gr.Button("Send a Message")
    input_btn.click(fn=capResponse, inputs=user_input, outputs=output)

    with gr.Row():
        gr.Examples(
            examples=[
                "What is a dog?",
                "How do I build a birdhouse?",
                "What is a derivative?",
                "Who is Barack Obama?",
            ],
            inputs=user_input,
            outputs=output,
            fn=capResponse,
            cache_examples=False,
        )

    with gr.Row():
        gr.Markdown(
        """    
        <div align="center"> Chat with CapGPT, because there's nothing better than a 'lil mistruthin. </div>
        """
        )

demo.launch()