Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,13 +19,14 @@ llm = ChatGoogleGenerativeAI(
|
|
| 19 |
google_api_key=GOOGLE_API_KEY
|
| 20 |
)
|
| 21 |
|
| 22 |
-
# Tavily
|
| 23 |
tavily_client = TavilyClient(api_key=TAVILY_API_KEY)
|
| 24 |
|
|
|
|
| 25 |
def extract_website_text(url):
|
| 26 |
result = tavily_client.extract(urls=url)
|
| 27 |
-
if result and "text" in result
|
| 28 |
-
return result[
|
| 29 |
return "Could not extract content from the URL."
|
| 30 |
|
| 31 |
# Prompt
|
|
@@ -33,9 +34,7 @@ prompt = PromptTemplate(
|
|
| 33 |
input_variables=["website_content", "question"],
|
| 34 |
template="""
|
| 35 |
You are an intelligent assistant. Based on the following website content:
|
| 36 |
-
|
| 37 |
{website_content}
|
| 38 |
-
|
| 39 |
Answer the following question:
|
| 40 |
{question}
|
| 41 |
"""
|
|
@@ -50,10 +49,4 @@ question = st.text_area("What do you want to ask about the website?")
|
|
| 50 |
|
| 51 |
if st.button("Get Answer"):
|
| 52 |
with st.spinner("Extracting and generating answer..."):
|
| 53 |
-
site_text =
|
| 54 |
-
result = qa_chain.invoke({
|
| 55 |
-
"website_content": site_text,
|
| 56 |
-
"question": question
|
| 57 |
-
})
|
| 58 |
-
st.subheader("✅ Answer")
|
| 59 |
-
st.write(result["text"])
|
|
|
|
| 19 |
google_api_key=GOOGLE_API_KEY
|
| 20 |
)
|
| 21 |
|
| 22 |
+
# Tavily client
|
| 23 |
tavily_client = TavilyClient(api_key=TAVILY_API_KEY)
|
| 24 |
|
| 25 |
+
# ✅ FIXED: extract website text
|
| 26 |
def extract_website_text(url):
|
| 27 |
result = tavily_client.extract(urls=url)
|
| 28 |
+
if result and "text" in result:
|
| 29 |
+
return result["text"]
|
| 30 |
return "Could not extract content from the URL."
|
| 31 |
|
| 32 |
# Prompt
|
|
|
|
| 34 |
input_variables=["website_content", "question"],
|
| 35 |
template="""
|
| 36 |
You are an intelligent assistant. Based on the following website content:
|
|
|
|
| 37 |
{website_content}
|
|
|
|
| 38 |
Answer the following question:
|
| 39 |
{question}
|
| 40 |
"""
|
|
|
|
| 49 |
|
| 50 |
if st.button("Get Answer"):
|
| 51 |
with st.spinner("Extracting and generating answer..."):
|
| 52 |
+
site_text = extract_websi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|