Vikrant26 commited on
Commit
9a31b36
·
verified ·
1 Parent(s): 81b1a2c

Upload 3 files

Browse files
Files changed (3) hide show
  1. .env +1 -0
  2. app.py +39 -0
  3. requirements.txt +4 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ GOOGLE_API_KEY="AIzaSyDnI8-gASsDS0_94frGkc-A3eQVgTvIHDk"
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Q&A Chatbot for Indian Constitution
2
+ from dotenv import load_dotenv
3
+ import streamlit as st
4
+ import os
5
+ import textwrap
6
+ import google.generativeai as genai
7
+ from IPython.display import Markdown
8
+
9
+ def to_markdown(text):
10
+ text = text.replace('•', ' *')
11
+ return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))
12
+
13
+ load_dotenv() # take environment variables from .env.
14
+
15
+ # Configure the Google API key
16
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
17
+
18
+ # Function to load Gemini model and get responses specifically about the Indian Constitution
19
+ def get_gemini_response(question):
20
+ model = genai.GenerativeModel('gemini-pro')
21
+ # Add a context to ensure responses are about the Indian Constitution
22
+ prompt = f"Answer the following question with respect to the Indian Constitution:\n\n{question}"
23
+ response = model.generate_content(prompt)
24
+ return response.text
25
+
26
+ # Initialize our Streamlit app
27
+ st.set_page_config(page_title="Q&A Demo - Indian Constitution")
28
+
29
+ st.header("Samvidhan Ko Jaano 📙📙")
30
+
31
+ input = st.text_input("Input: ", key="input")
32
+
33
+ submit = st.button("Ask the question")
34
+
35
+ # If ask button is clicked
36
+ if submit:
37
+ response = get_gemini_response(input)
38
+ st.subheader("The Response is")
39
+ st.write(response)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ google-api-core
3
+ google-cloud-language
4
+ openai