edithram23 commited on
Commit
4b41cf9
·
verified ·
1 Parent(s): 13ac4f8

Rename gemini_app.py to app.py

Browse files
Files changed (1) hide show
  1. gemini_app.py → app.py +71 -72
gemini_app.py → app.py RENAMED
@@ -1,72 +1,71 @@
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
-
 
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
+
7
+ genai.configure(api_key=os.getenv('GEMINI'))
8
+ database_str=''
9
+ with open('data_base.txt', 'r',encoding='utf-8') as f:
10
+ database_str = f.read()
11
+
12
+
13
+ def generate_response(query):
14
+ prompt = f'''
15
+ You are a Course suggestor based on the user requirement and the from the given database which consist of
16
+ the course name and description of the course.
17
+
18
+ You're tasked to use the description of each course and compare it with the user input and output which course's
19
+ description matches the user requirement.
20
+ Output the course name & Course Link alone which matches the user requirement.
21
+ 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
22
+
23
+ # Database
24
+ {database_str}
25
+
26
+ # User Input
27
+ {query}
28
+
29
+ # Output : Course Name||Coure LINK \ Course Name||Course LINK \....
30
+ '''
31
+ model = genai.GenerativeModel("gemini-1.5-flash")
32
+ response = model.generate_content(prompt)
33
+ return response.text.split("\\")
34
+
35
+
36
+ # Define session state variables
37
+ if 'messages' not in st.session_state:
38
+ st.session_state.messages = []
39
+ if 'mess' not in st.session_state:
40
+ st.session_state.mess=[]
41
+
42
+
43
+ if st.sidebar.button("RESET"):
44
+ st.session_state.messages=[]
45
+ st.session_state.mess=[]
46
+
47
+ # User input
48
+ st.title('Analytics Vidhya Course Finder')
49
+ user_input = st.chat_input('Write your message here...')
50
+
51
+ if user_input:
52
+ # Append user input to messages
53
+ st.session_state.messages.append({"role": "user", "content": user_input})
54
+ st.session_state.mess+=[user_input]
55
+ # Generate chatbot response
56
+ bot_response = generate_response(st.session_state.mess)
57
+ st.session_state.messages.append({"role": "bot", "content": bot_response})
58
+
59
+ # Display chat messages in correct order
60
+ for message in st.session_state.messages:
61
+ if message["role"] == "user":
62
+ with st.chat_message("human"):
63
+ st.write(message['content'])
64
+ else:
65
+ with st.chat_message("ai"):
66
+ for i in message['content']:
67
+ name = i.split('||')[0]
68
+ link = i.split("||")[1]
69
+ st.markdown(f"[{name}]({link})", unsafe_allow_html=True)
70
+
71
+