Spaces:
Paused
Paused
File size: 4,772 Bytes
0d283e9 af80b79 228f50e f0889f5 0d283e9 956825f 0d283e9 3cdd448 b1f8283 3cdd448 0d283e9 3cdd448 0d283e9 956825f 0d283e9 3cdd448 0d283e9 cdc0fe8 0d283e9 3cdd448 a503292 0d283e9 3cdd448 0d283e9 9dbce44 956825f 3cdd448 0d283e9 51307f7 0d283e9 a503292 0d283e9 3cdd448 0d283e9 3cdd448 0d283e9 956825f 3cdd448 |
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 |
import gradio as gr
from ask import askQuestion
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 = ["Research & Summarize"]
prompt_enhancers = ["""Please act as a researcher and summarizer for the [TOPIC] I list at the end of this prompt. Create a concise, accurate, and objective summary of the main points and findings. Use clear headlines, bullet points, and sub-bullet points where needed. Keep in mind the following guidelines:
Avoid personal opinions or interpretations; focus on objectively presenting the information.
Write the summary in your own words.
Reference data sources when necessary.
Ensure the summary is clear and concise.
Please write in English language.
"""]
bg_color = "#c5dde0"
s_color = "#1d2230"
mycss = """
.gradio-container {{background-color: {bgcolor}}}
#title {{margin-top:33%;margin-bottom:25px;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;border-width:0;box-shadow:none}}
#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:29px}}
"""
formatted_css = mycss.format(bgcolor=bg_color, scolor=s_color)
def handleSubmit(brain_name, enhancer, question, temperature, maxTokens):
print(brain_name)
if (brain_name == "" and question == ""):
return "Please select Brain Name & Enter Question"
if (brain_name == ""):
return "Please select Brain Name"
if (question == ""):
return "Please Enter Question"
if (enhancer != ""):
promptIndex = prompt_names.index(enhancer)
question = prompt_enhancers[promptIndex]+question
return askQuestion(brain_name, question, 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"):
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.5, 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(label="Submit", elem_id="button")
with gr.Column(scale=1, elem_id="outputCol",):
output_text = gr.TextArea(
label="Brain Output", lines=17, elem_id="output").style(show_copy_button=True)
submit_button.click(
handleSubmit, [brain_name, enhancer_name, question, temperature, maxTokens], output_text)
block_demo.load(getBrains, [], brain_name)
block_demo.launch(show_api=False) |