sunnysharma20 commited on
Commit
a206c6b
·
verified ·
1 Parent(s): 17a07c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -50
app.py CHANGED
@@ -1,63 +1,39 @@
 
 
 
 
1
  import os
2
  import google.generativeai as genai
3
- import streamlit as st
 
4
 
5
- # Create a function for getting a response from Gemini
6
 
 
7
  def get_response(question):
8
- try:
9
- # Ensure the API key is correctly retrieved
10
- api_key = os.getenv("AIzaSyCUOZsk6wPiJvDeHjfBAoqPo3sGjHFdsN0Y") # Use environment variable for API key
11
- if not api_key:
12
- raise ValueError("API key for Gemini is missing.")
13
-
14
- # Configure API
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="Ask GPT", page_icon=":robot:")
47
- st.header("Ask GPT Application")
48
 
49
- # Create function for taking user input
50
  def get_user_input():
51
- text = st.text_input("Ask:", key="input")
52
- return text # Return the user input text
53
 
54
- # Display the input and response after submission
55
  user_input = get_user_input()
 
56
 
57
- # Submit Button
58
- submit = st.button("Ask")
59
 
60
- if submit and user_input:
61
- resp = get_response(user_input) # Call the get_response function
62
- st.subheader("Answer: ")
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)