Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +40 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
from datetime import datetime
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
import google.generativeai as genai
|
6 |
+
|
7 |
+
|
8 |
+
# Load environment variables from .env file
|
9 |
+
load_dotenv()
|
10 |
+
|
11 |
+
# Access the GEMINI_API_KEY from the environment variables
|
12 |
+
api_key = "AIzaSyCgwV3oXhiERE9l_tB1-RM4j4HFDSHd4jI"
|
13 |
+
|
14 |
+
# Configure the Generative AI API with the key
|
15 |
+
genai.configure(api_key=api_key)
|
16 |
+
|
17 |
+
# Initialize the GenerativeModel
|
18 |
+
model = genai.GenerativeModel('gemini-1.5-flash')
|
19 |
+
|
20 |
+
def responceFromModel(user_input):
|
21 |
+
response = model.generate_content(user_input)
|
22 |
+
return response.text
|
23 |
+
|
24 |
+
# Configure page
|
25 |
+
st.set_page_config(page_title="Chatbot", page_icon="🤖", layout="centered")
|
26 |
+
|
27 |
+
# streamlit UI
|
28 |
+
st.title("🤖GEMINI ChatBot")
|
29 |
+
st.subheader("Designed by M. Abbas ")
|
30 |
+
st.write("It uses Google API")
|
31 |
+
|
32 |
+
|
33 |
+
user_input = st.text_input("Enter your prompt: ")
|
34 |
+
if st.button("Get response"):
|
35 |
+
if user_input:
|
36 |
+
output = responceFromModel(user_input)
|
37 |
+
st.write(f"ChatBot response: \n {output}")
|
38 |
+
else:
|
39 |
+
st.write("Please enter a prompt")
|
40 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
python-dotenv
|
2 |
+
streamlit
|