Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,63 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import google.generativeai as genai
|
| 3 |
-
import
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
|
|
|
|
| 7 |
def get_response(question):
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
genai.configure(api_key=api_key)
|
| 16 |
-
|
| 17 |
-
# Define the generation configuration
|
| 18 |
-
generation_config = {
|
| 19 |
-
"temperature": 1,
|
| 20 |
-
"top_p": 0.95,
|
| 21 |
-
"top_k": 40,
|
| 22 |
-
"max_output_tokens": 8192,
|
| 23 |
-
"response_mime_type": "text/plain",
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
# Initialize the model
|
| 27 |
-
model = genai.GenerativeModel(
|
| 28 |
-
model_name="gemini-1.5-pro-002",
|
| 29 |
-
generation_config=generation_config,
|
| 30 |
-
)
|
| 31 |
-
|
| 32 |
-
# Start a chat session (can be empty or with history)
|
| 33 |
-
chat_session = model.start_chat(history=[])
|
| 34 |
-
|
| 35 |
-
# Send the message and get the response
|
| 36 |
-
response = chat_session.send_message(question)
|
| 37 |
-
|
| 38 |
-
# Ensure response is correctly parsed (adjust if needed based on response format)
|
| 39 |
-
return response.get("text", "No text response found.")
|
| 40 |
-
|
| 41 |
-
except Exception as e:
|
| 42 |
-
# Handle any exceptions that occur during the process
|
| 43 |
-
return f"Error: {str(e)}"
|
| 44 |
|
| 45 |
# Using Streamlit for generation of page
|
| 46 |
-
st.set_page_config(page_title="
|
| 47 |
-
st.header("
|
| 48 |
|
| 49 |
-
# Create function for taking user input
|
| 50 |
def get_user_input():
|
| 51 |
-
text = st.text_input("Ask:", key="input")
|
| 52 |
-
return text
|
| 53 |
|
| 54 |
-
# Display the input and response after submission
|
| 55 |
user_input = get_user_input()
|
|
|
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
submit = st.button("Ask")
|
| 59 |
|
| 60 |
-
if submit
|
| 61 |
-
|
| 62 |
-
st.
|
| 63 |
-
st.write(resp) # Display the response
|
|
|
|
| 1 |
+
import keyfile
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from langchain_openai import OpenAI
|
| 4 |
+
import getpass
|
| 5 |
import os
|
| 6 |
import google.generativeai as genai
|
| 7 |
+
import pandas as pd
|
| 8 |
+
|
| 9 |
|
| 10 |
+
genai.configure(api_key=keyfile.GEMINI_API_KEY)
|
| 11 |
|
| 12 |
+
# Creating a function for getting the responses from OpenAI
|
| 13 |
def get_response(question):
|
| 14 |
+
# os.environ["OPENAI_API_KEY"] = keyfile.OPENAI_API_KEY
|
| 15 |
+
# llm = OpenAI()
|
| 16 |
+
# answer = llm.invoke(question)
|
| 17 |
+
# return answer
|
| 18 |
+
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 19 |
+
response = model.generate_content(question)
|
| 20 |
+
return response.text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# Using Streamlit for generation of page
|
| 23 |
+
st.set_page_config(page_title = "ASK GPT / GEMINI", page_icon = ":robot:")
|
| 24 |
+
st.header("ASK GPT / GEMINI Application")
|
| 25 |
|
| 26 |
+
# Create a function for taking user input
|
| 27 |
def get_user_input():
|
| 28 |
+
text = st.text_input("Ask: ", key = "input")
|
| 29 |
+
return text
|
| 30 |
|
|
|
|
| 31 |
user_input = get_user_input()
|
| 32 |
+
resp = get_response(user_input)
|
| 33 |
|
| 34 |
+
# Submission button
|
| 35 |
+
submit = st.button("Ask!")
|
| 36 |
|
| 37 |
+
if submit:
|
| 38 |
+
st.subheader("Answer to the query: ")
|
| 39 |
+
st.write(resp)
|
|
|