Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
|
| 4 |
+
load_dotenv() # take environment variables from .env.
|
| 5 |
+
|
| 6 |
+
import streamlit as st
|
| 7 |
+
import os
|
| 8 |
+
import pathlib
|
| 9 |
+
import textwrap
|
| 10 |
+
|
| 11 |
+
import google.generativeai as genai
|
| 12 |
+
|
| 13 |
+
from IPython.display import display
|
| 14 |
+
from IPython.display import Markdown
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
os.getenv("GOOGLE_API_KEY")
|
| 18 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 19 |
+
|
| 20 |
+
## Function to load OpenAI model and get respones
|
| 21 |
+
model = genai.GenerativeModel('gemini-pro')
|
| 22 |
+
chat = model.start_chat(history=[])
|
| 23 |
+
def get_gemini_response(question):
|
| 24 |
+
|
| 25 |
+
response =chat.send_message(question,stream=True)
|
| 26 |
+
return response
|
| 27 |
+
|
| 28 |
+
##initialize our streamlit app
|
| 29 |
+
|
| 30 |
+
st.set_page_config(page_title="Q&A Demo")
|
| 31 |
+
|
| 32 |
+
st.header("Gemini Application")
|
| 33 |
+
|
| 34 |
+
input=st.text_input("Input: ",key="input")
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
submit=st.button("Ask the question")
|
| 38 |
+
|
| 39 |
+
## If ask button is clicked
|
| 40 |
+
|
| 41 |
+
if submit:
|
| 42 |
+
|
| 43 |
+
response=get_gemini_response(input)
|
| 44 |
+
st.subheader("The Response is")
|
| 45 |
+
for chunk in response:
|
| 46 |
+
print(st.write(chunk.text))
|
| 47 |
+
print("_"*80)
|
| 48 |
+
|
| 49 |
+
st.write(chat.history)
|