SKJ / app.py
Vikrant26's picture
Upload 3 files
9a31b36 verified
# Q&A Chatbot for Indian Constitution
from dotenv import load_dotenv
import streamlit as st
import os
import textwrap
import google.generativeai as genai
from IPython.display import Markdown
def to_markdown(text):
text = text.replace('β€’', ' *')
return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))
load_dotenv() # take environment variables from .env.
# Configure the Google API key
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
# Function to load Gemini model and get responses specifically about the Indian Constitution
def get_gemini_response(question):
model = genai.GenerativeModel('gemini-pro')
# Add a context to ensure responses are about the Indian Constitution
prompt = f"Answer the following question with respect to the Indian Constitution:\n\n{question}"
response = model.generate_content(prompt)
return response.text
# Initialize our Streamlit app
st.set_page_config(page_title="Q&A Demo - Indian Constitution")
st.header("Samvidhan Ko Jaano πŸ“™πŸ“™")
input = st.text_input("Input: ", key="input")
submit = st.button("Ask the question")
# If ask button is clicked
if submit:
response = get_gemini_response(input)
st.subheader("The Response is")
st.write(response)