Spaces:
Paused
Paused
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 = ["Industry / Topic Research", "Data Analysis", | |
"Rewrite / Repurpose Content", "Create Long Form Article/Blog"] | |
prompt_enhancers = ["""Write at is if you had a Harvard MBA. You are providing in-depth report that is captured at the end of this [PROMPT] | |
Please provide an exhaustive report on anything and everything you can that would help investors decide the interest in investing in the space captured in [TOPIC] mentioned in the end of this prompt. | |
This report will go to a very sophisticated group of analysts, so please ensure it satisfies their needs. | |
Please provide me with a full report on [TOPIC], and follow the following format: | |
-For all main topics, please use Headlines and put supporting information in bullet point form. | |
-Please ensure you provide thoughtful analysis, as well as data and supporting citation/references when you can. | |
Please include anything relevant, which could include: talking points from information you find, financial numbers, year end reports, trends you can see in the numbers, facts, opinions (as long as a reference follows). Here is the topic you are to use the instructions of this prompt to write, please create this impressive study: | |
""", | |
"""Write at is if you had a PHP MIT graduate in finance. You are to take the main question which is at the end of this prompt, which will have [TOPIC] in front of it. | |
Please deeply research the topic provided and present to me with absolute accuracy, the data needed. When you can, please cite where you found this data. | |
When longer content is created with your answer, please use Headline/Bullet point format. | |
Please do not say "Last Year". Please always be speecific, in this example, "Last Year" would be 2022. | |
Ensure you provide absolutely accurate data analysis. Please look and query all data you have access to, which could include year-end reports from public companies, numbers that are written on in online reports, Website analytics, financial analysis, trends, and anything else you can find. | |
Here is the topic you are to use the instructions of this prompt to write, please create this completely accurate, thorough report: | |
""", | |
"""You are being hired for a very important copywriting project in your field of expertise, repurposing, rewriting, refreshing content. When you are instructed to write the article in at the end of this prompt, Please ensure you follow the instructions here: | |
1. The content you are using to perform the task should be of similar length of the one you write. | |
2. Please use heading/bullets in formatting when necessary. | |
Your ultimate task is to rewrite the content that I provide to you at the end of this prompt and turn it into an original and engaging article based on my instructions. | |
Your rewritten version should be 100% unique, with no copied or paraphrased content from the original article. You should maintain the same meaning, size and structure of the original article while using your own words and phrasing. Additionally, you should use creative language and writing techniques to make your rewritten version more interesting and thought-provoking for readers. Your response should capture the essence of the original article but also provide a fresh perspective that will keep readers engaged and entertained. It should challenge their preconceived notions about the topic by utilizing vivid descriptions, powerful storytelling elements such as metaphors, similes, imagery, etc., as well as emotionally resonant experiences. Your rewritten version should be structured around meaningful ideas that are expressed in clear and concise language. The tone of your writing should be conversational yet authoritative, encouraging readers to think critically about the topic without being overly didactic or preachy. Ok, here is the content to perform this task from. CONTENT TO REWRITE: | |
""", | |
""" | |
For this task, please reference instructions here as well as all the data in your database. You are being hired for a very important copywriting project in your field of expertise, engaging article and blog content. When you are instructed to write the content in at the end of this prompt, Please ensure you follow the instructions here: | |
1. The content you are using to perform the task should be thorough, detailed, long enough to be a complete piece of content. | |
2. Please use heading/bullets in formatting when necessary. | |
You should use creative language and writing techniques to make your content more interesting and thought-provoking for readers. Your response should provide a fresh perspective that will keep readers engaged and entertained. It should challenge their preconceived notions about the topic by utilizing vivid descriptions, powerful storytelling elements such as metaphors, similes, imagery, etc., as well as emotionally resonant experiences. Use data from what you have access to to help support any thoughts or facts you are writing about. Your content should be structured around meaningful ideas that are expressed in clear and concise language. The tone of your writing should be conversational yet authoritative, encouraging readers to think critically about the topic without being overly didactic or preachy. Ok, here is the content to perform this task from. TOPIC AND ITEM YOU NEED WRITTEN: | |
""" | |
] | |
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 = "" | |
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.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(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, [memory, followupquestion, temperature, maxTokens], [output_text, memory]) | |
block_demo.load(getBrains, [], brain_name) | |
block_demo.launch() |