Spaces:
Runtime error
Runtime error
import os | |
import streamlit as st | |
from dotenv import load_dotenv | |
from Bard import Chatbot | |
import asyncio | |
import tqdm | |
import time | |
loop = asyncio.new_event_loop() | |
asyncio.set_event_loop(loop) | |
load_dotenv() | |
WEBSOCKET_TIMEOUT_MS = 10000 | |
def get_token(): | |
with st.form(key="BARD_API_form"): | |
st.markdown( | |
"## BARD API token \n Go to https://bard.google.com/ \n " | |
"- F12 for console \n " | |
"- Copy the values of the cookies: \n " | |
" - Session: Go to Application β Cookies β `__Secure-1PSID`. Copy the value of that cookie." | |
) | |
psid = st.text_input(label="Enter your __Secure-1PSID token") | |
psidts = st.text_input(label="Enter your __Secure-1PSIDTS token") | |
submit_button = st.form_submit_button(label="Submit") | |
return psid, psidts, submit_button | |
def prompt_letter(): | |
""" | |
This function creates a form with input fields for various information required to generate a cover letter. | |
It prompts the user to enter their __Secure-1PSID and __Secure-1PSIDTS tokens, company name, role they are applying for, | |
contact person, their name, personal experience, job description, and their passion. | |
The function then returns the entered __Secure-1PSID token, __Secure-1PSIDTS token, a cover letter prompt, and a submit button. | |
:return: A tuple containing the entered __Secure-1PSID token, __Secure-1PSIDTS token, cover letter prompt, and submit button. | |
""" | |
with st.form(key="my_form_to_submit"): | |
st.markdown( | |
"## BARD API token\n" | |
"Go to https://bard.google.com/\n" | |
"- F12 for console\n" | |
"- Copy the values of the cookies:\n" | |
" - Session: Go to Application β Cookies β `__Secure-1PSID` and `__Secure-1PSIDTS`. Copy the value of both cookies respectively." | |
) | |
psid = st.text_input( | |
label="Enter your __Secure-1PSID", | |
max_chars=100, | |
type="default", | |
placeholder="Place yours PSID. It ends with a dot.", | |
) | |
psidts = st.text_input( | |
label="Enter your __Secure-1PSIDTS", | |
max_chars=100, | |
type="default", | |
placeholder="Place yours PSIDTS...", | |
) | |
company_name = st.text_input("Company Name: ", "Google") | |
role = st.text_input( | |
"What role are you applying for? ", "Machine Learning Engineer" | |
) | |
contact_person = st.text_input("Who are you emailing? ", "Hiring Manager") | |
your_name = st.text_input("What is your name? ", "Hari Bahadur") | |
personal_exp = st.text_input( | |
"I have experience in...", | |
"natural language processing, fraud detection, statistical modeling, and machine learning algorithms. ", | |
) | |
job_desc = st.text_input( | |
"I am excited about the job because...", | |
"this role will allow me to work on technically challenging problems and create impactful solutions while working with an innovative team. ", | |
) | |
passion = st.text_input( | |
"I am passionate about...", | |
"solving problems at the intersection of technology and social good.", | |
) | |
# make progress bar using stremalit | |
with st.spinner("Please wait..."): | |
time.sleep(1) | |
submit_button = st.form_submit_button(label="Submit") | |
prompt = ( | |
"Write a cover letter to " | |
+ contact_person | |
+ " from " | |
+ your_name | |
+ " for a " | |
+ role | |
+ " job at " | |
+ company_name | |
+ "." | |
+ " I have experience in " | |
+ personal_exp | |
+ " I am excited about the job because " | |
+ job_desc | |
+ " I am passionate about " | |
+ passion | |
) | |
return psid, psidts, prompt, submit_button | |
psid, psidts, prompt, submit_button = prompt_letter() | |
if submit_button: | |
chatbot = Chatbot(psid, psidts) | |
ans = chatbot.ask(prompt) | |
st.write("\n _Please read it carefully and make changes as needed._ \n") | |
st.write(ans["content"]) | |