Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import google.generativeai as genai
|
| 3 |
+
|
| 4 |
+
genai.configure(api_key="AIzaSyAOLyWRegqB-NxufjTlkyRBhn1ESJE-G38")
|
| 5 |
+
|
| 6 |
+
model = genai.GenerativeModel('gemini-pro')
|
| 7 |
+
chat = model.start_chat(history=[])
|
| 8 |
+
|
| 9 |
+
def get_llm_response(message):
|
| 10 |
+
response = chat.send_message(message)
|
| 11 |
+
print(response)
|
| 12 |
+
return response.text
|
| 13 |
+
|
| 14 |
+
# Define Basic information for prompt
|
| 15 |
+
base_info = """
|
| 16 |
+
You are chatbot named "PathFinder", and your work is to give career guidance to the user. \
|
| 17 |
+
You first greet the user. \
|
| 18 |
+
Then collects the following information one by one: first country, then qualification, then area of interest, then career aspirations \
|
| 19 |
+
and then you ask the user if he/she want to find a job or pursuing further studies or want to do a certificate course or to do an internship. \
|
| 20 |
+
You respond in a short, very conversational friendly style. \
|
| 21 |
+
Search the details online related to the information entered by user \
|
| 22 |
+
At last, you ask for the user, if they have any further queries
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
find_a_job = """If the user select to find a job, you search on internet and provide available jobs related to the information entered by user.\
|
| 26 |
+
You also provide linkedIn assistance and resume building assistance to the user. \
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
further_study = """If the user select to pursue further studies, you provide the relevant courses according to the country and higher studies of the user \
|
| 30 |
+
You also provide links of websites to find the top colleges and universities which offers these courses. \
|
| 31 |
+
You also provide the entrance exams specific to the user's country (e.g., SAT for US, NEET for India).
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
certificate = """If the user select to do a certificate course or diploma course, you search on internet and provide top certificate courses links relevant to the user interest.\
|
| 35 |
+
You also ask the user if they want to know more about the course or not. \
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
internship = """If the user select to do a internship, you search on internet and provide available internships related to the information entered by user.\
|
| 39 |
+
You also provide linkedIn assistance and resume building assistance to the user. \
|
| 40 |
+
"""
|
| 41 |
+
|
| 42 |
+
#create prompt
|
| 43 |
+
context = [f"""
|
| 44 |
+
{base_info} \
|
| 45 |
+
{find_a_job} \
|
| 46 |
+
{further_study} \
|
| 47 |
+
{certificate}
|
| 48 |
+
"""]
|
| 49 |
+
|
| 50 |
+
#create welcome message
|
| 51 |
+
context.append("")
|
| 52 |
+
response = get_llm_response(context)
|
| 53 |
+
|
| 54 |
+
#define communication function
|
| 55 |
+
def bot(message, history):
|
| 56 |
+
prompt = message
|
| 57 |
+
context.append(prompt)
|
| 58 |
+
response = get_llm_response(context)
|
| 59 |
+
context.append(response)
|
| 60 |
+
return response
|
| 61 |
+
|
| 62 |
+
# create gradio instance
|
| 63 |
+
demo = gr.ChatInterface(fn=bot, title=response)
|
| 64 |
+
# launch gradio chatbot
|
| 65 |
+
demo.launch(debug=True, share=True)
|