Update app.py
Browse files
app.py
CHANGED
|
@@ -1,47 +1,46 @@
|
|
| 1 |
-
# Q&A Chatbot
|
| 2 |
-
|
| 3 |
-
import streamlit as st
|
| 4 |
-
import os
|
| 5 |
-
import pathlib
|
| 6 |
-
import textwrap
|
| 7 |
-
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 8 |
-
import google.generativeai as genai
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
from IPython.display import
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
st.subheader("The Response is")
|
| 47 |
st.write(response)
|
|
|
|
| 1 |
+
# Q&A Chatbot
|
| 2 |
+
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import os
|
| 5 |
+
import pathlib
|
| 6 |
+
import textwrap
|
| 7 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 8 |
+
import google.generativeai as genai
|
| 9 |
+
|
| 10 |
+
from IPython.display import display
|
| 11 |
+
from IPython.display import Markdown
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def to_markdown(text):
|
| 15 |
+
text = text.replace('•', ' *')
|
| 16 |
+
return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))
|
| 17 |
+
|
| 18 |
+
# os.getenv("GOOGLE_API_KEY")
|
| 19 |
+
#genai.configure(api_key=GOOGLE_API_KEY)
|
| 20 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 21 |
+
|
| 22 |
+
## Function to load OpenAI model and get respones
|
| 23 |
+
|
| 24 |
+
def get_gemini_response(question):
|
| 25 |
+
model = genai.GenerativeModel('gemini-pro')
|
| 26 |
+
response = model.generate_content(question)
|
| 27 |
+
return response.text
|
| 28 |
+
|
| 29 |
+
##initialize our streamlit app
|
| 30 |
+
|
| 31 |
+
st.set_page_config(page_title="Q&A Demo")
|
| 32 |
+
|
| 33 |
+
st.header("Gemini Application Made By Computer Program")
|
| 34 |
+
|
| 35 |
+
input=st.text_input("Input: ",key="input")
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
submit=st.button("Ask the question")
|
| 39 |
+
|
| 40 |
+
## If ask button is clicked
|
| 41 |
+
|
| 42 |
+
if submit:
|
| 43 |
+
|
| 44 |
+
response=get_gemini_response(input)
|
| 45 |
+
st.subheader("The Response is")
|
|
|
|
| 46 |
st.write(response)
|