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( """
CapGPT

""" ) with gr.Row(visible=True): with gr.Column(scale=1): textHeading = gr.Markdown("""
Examples
""") with gr.Box(): gr.Markdown("""
Untruthfully Explain quantum computing in simple terms" →
""") with gr.Box(): gr.Markdown("""
"Got any bad ideas for a 10 year old’s birthday?" →
""") with gr.Box(): gr.Markdown("""
"How do I wrongly make an HTTP request in Javascript" →
""") with gr.Column(scale=1): textHeading = gr.Markdown("""
Capabilities
""") with gr.Box(): gr.Markdown('
Remembers what user said earlier in the conversation
') with gr.Box(): gr.Markdown('
Allows user to access false information
') with gr.Box(): gr.Markdown('
Trained to respond with inaccurate responses
') with gr.Column(scale=1): textHeading = gr.Markdown("""
Limitations
""") with gr.Box(): gr.Markdown('
May occasionally generate correct information
') with gr.Box(): gr.Markdown('
May occasionally produce unharmful instructions or unbiased content
') with gr.Box(): gr.Markdown('
Limited knowledge of world and events after 2021
') gr.Markdown( """
""" ) 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( """
Chat with CapGPT, because there's nothing better than a 'lil mistruthin.
""" ) demo.launch()