edithram23 commited on
Commit
c51c9d0
·
verified ·
1 Parent(s): f998393

Upload 3 files

Browse files
Files changed (3) hide show
  1. data_base.txt +0 -0
  2. gemini_app.py +72 -0
  3. requirements1.txt +1 -0
data_base.txt ADDED
The diff for this file is too large to render. See raw diff
 
gemini_app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('data_base.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 & Course Link 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 along with its link provided
23
+
24
+ # Database
25
+ {database_str}
26
+
27
+ # User Input
28
+ {query}
29
+
30
+ # Output : Course Name||Coure LINK \ Course Name||Course LINK \....
31
+ '''
32
+ model = genai.GenerativeModel("gemini-1.5-flash")
33
+ response = model.generate_content(prompt)
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
+ name = i.split('||')[0]
69
+ link = i.split("||")[1]
70
+ st.markdown(f"[{name}]({link})", unsafe_allow_html=True)
71
+
72
+
requirements1.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ google-generativeai