rahulgupta007 commited on
Commit
99d0e43
·
verified ·
1 Parent(s): b789988

Create app.py

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