Spaces:
Runtime error
Runtime error
gemini support
Browse files- app.py +21 -4
- requirements.txt +2 -1
app.py
CHANGED
@@ -12,11 +12,17 @@ import os, asyncio, trafilatura
|
|
12 |
from langchain.docstore.document import Document
|
13 |
import requests
|
14 |
from langchain_openai import ChatOpenAI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
load_dotenv()
|
17 |
|
18 |
-
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
|
19 |
-
openai.api_key = os.getenv("OPENAI_API_KEY")
|
20 |
|
21 |
@st.cache_resource
|
22 |
def get_url_name(url):
|
@@ -55,7 +61,13 @@ class WebpageQATool(BaseTool):
|
|
55 |
raise NotImplementedError
|
56 |
|
57 |
def run_llm(url, query):
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
query_website_tool = WebpageQATool(qa_chain=load_qa_with_sources_chain(llm))
|
60 |
result = query_website_tool._run(url, query) # Pass the URL and query as arguments
|
61 |
return result
|
@@ -64,6 +76,11 @@ st.markdown("<h1 style='text-align: center; color: green;'>Info Retrieval from W
|
|
64 |
st.markdown("<h3 style='text-align: center; color: green;'>Developed by <a href='https://github.com/AIAnytime'>AI Anytime with ❤️ </a></h3>", unsafe_allow_html=True)
|
65 |
st.markdown("<h2 style='text-align: center; color:red;'>Enter the Website URL 👇</h2>", unsafe_allow_html=True)
|
66 |
|
|
|
|
|
|
|
|
|
|
|
67 |
input_url = st.text_input("Enter the URL")
|
68 |
|
69 |
if len(input_url)>0:
|
|
|
12 |
from langchain.docstore.document import Document
|
13 |
import requests
|
14 |
from langchain_openai import ChatOpenAI
|
15 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
options = ["openai","gemini"]
|
20 |
+
# 创建下拉选项框
|
21 |
+
selected_option = st.selectbox("select your llm:", options)
|
22 |
+
|
23 |
+
api_key = st.text_input("enter your llm api key:")
|
24 |
|
|
|
25 |
|
|
|
|
|
26 |
|
27 |
@st.cache_resource
|
28 |
def get_url_name(url):
|
|
|
61 |
raise NotImplementedError
|
62 |
|
63 |
def run_llm(url, query):
|
64 |
+
if selected_option == "openai":
|
65 |
+
os.environ["OPENAI_API_KEY"] = api_key
|
66 |
+
llm = ChatOpenAI(temperature=0.5)
|
67 |
+
if selected_option == "gemini":
|
68 |
+
os.environ["GOOGLE_API_KEY"] = api_key
|
69 |
+
llm = ChatGoogleGenerativeAI(temperature=0.5)
|
70 |
+
# llm = ChatOpenAI(temperature=0.5)
|
71 |
query_website_tool = WebpageQATool(qa_chain=load_qa_with_sources_chain(llm))
|
72 |
result = query_website_tool._run(url, query) # Pass the URL and query as arguments
|
73 |
return result
|
|
|
76 |
st.markdown("<h3 style='text-align: center; color: green;'>Developed by <a href='https://github.com/AIAnytime'>AI Anytime with ❤️ </a></h3>", unsafe_allow_html=True)
|
77 |
st.markdown("<h2 style='text-align: center; color:red;'>Enter the Website URL 👇</h2>", unsafe_allow_html=True)
|
78 |
|
79 |
+
|
80 |
+
|
81 |
+
input_url = st.dropdown("Please Select you llm")
|
82 |
+
|
83 |
+
|
84 |
input_url = st.text_input("Enter the URL")
|
85 |
|
86 |
if len(input_url)>0:
|
requirements.txt
CHANGED
@@ -4,4 +4,5 @@ openai
|
|
4 |
trafilatura
|
5 |
streamlit
|
6 |
python-dotenv
|
7 |
-
langchain_openai
|
|
|
|
4 |
trafilatura
|
5 |
streamlit
|
6 |
python-dotenv
|
7 |
+
langchain_openai
|
8 |
+
langchain-google-genai
|