Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- database.txt +0 -0
- gemini_app.py +68 -0
- requirements1.txt +1 -0
database.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
gemini_app.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import google.generativeai as genai
|
3 |
+
import pandas as pd
|
4 |
+
import os
|
5 |
+
import numpy as np
|
6 |
+
from dotenv import load_dotenv
|
7 |
+
load_dotenv()
|
8 |
+
genai.configure(api_key=os.getenv('GEMINI'))
|
9 |
+
database_str=''
|
10 |
+
with open('database.txt', 'r',encoding='utf-8') as f:
|
11 |
+
database_str = f.read()
|
12 |
+
|
13 |
+
|
14 |
+
def generate_response(query):
|
15 |
+
prompt = f'''
|
16 |
+
You are a Course suggestor based on the user requirement and the from the given database which consist of
|
17 |
+
the course name and description of the course.
|
18 |
+
|
19 |
+
You're tasked to use the description of each course and compare it with the user input and output which course's
|
20 |
+
description matches the user requirement.
|
21 |
+
Output the course name alone which matches the user requirement.
|
22 |
+
you may output a max of 3 courses if you find that are good matches. name of the course should be exactly same as the database provided to you.
|
23 |
+
# Database
|
24 |
+
{database_str}
|
25 |
+
|
26 |
+
# User Input
|
27 |
+
{query}
|
28 |
+
|
29 |
+
# Output : (Course Name with | as splitter)
|
30 |
+
'''
|
31 |
+
model = genai.GenerativeModel("gemini-1.5-flash")
|
32 |
+
response = model.generate_content(prompt)
|
33 |
+
|
34 |
+
return response.text.split("|")
|
35 |
+
|
36 |
+
|
37 |
+
# Define session state variables
|
38 |
+
if 'messages' not in st.session_state:
|
39 |
+
st.session_state.messages = []
|
40 |
+
if 'mess' not in st.session_state:
|
41 |
+
st.session_state.mess=[]
|
42 |
+
|
43 |
+
|
44 |
+
if st.sidebar.button("RESET"):
|
45 |
+
st.session_state.messages=[]
|
46 |
+
st.session_state.mess=[]
|
47 |
+
|
48 |
+
# User input
|
49 |
+
st.title('Analytics Vidhya Course Finder')
|
50 |
+
user_input = st.chat_input('Write your message here...')
|
51 |
+
|
52 |
+
if user_input:
|
53 |
+
# Append user input to messages
|
54 |
+
st.session_state.messages.append({"role": "user", "content": user_input})
|
55 |
+
st.session_state.mess+=[user_input]
|
56 |
+
# Generate chatbot response
|
57 |
+
bot_response = generate_response(st.session_state.mess)
|
58 |
+
st.session_state.messages.append({"role": "bot", "content": bot_response})
|
59 |
+
|
60 |
+
# Display chat messages in correct order
|
61 |
+
for message in st.session_state.messages:
|
62 |
+
if message["role"] == "user":
|
63 |
+
with st.chat_message("human"):
|
64 |
+
st.write(message['content'])
|
65 |
+
else:
|
66 |
+
with st.chat_message("ai"):
|
67 |
+
for i in message['content']:
|
68 |
+
st.write('* '+i)
|
requirements1.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
google-generativeai
|