Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1878,6 +1878,8 @@ def handle_document_query(query):
|
|
| 1878 |
# Extract document name from the query
|
| 1879 |
doc_name_match = re.search(r"[\"']?([^\"']+\.(pdf|docx|doc|txt))[\"']?", query, re.IGNORECASE)
|
| 1880 |
doc_name = doc_name_match.group(1) if doc_name_match else None
|
|
|
|
|
|
|
| 1881 |
if not doc_name:
|
| 1882 |
return "Please specify a document name in your query."
|
| 1883 |
|
|
@@ -1888,12 +1890,12 @@ def handle_document_query(query):
|
|
| 1888 |
if error:
|
| 1889 |
return error
|
| 1890 |
|
| 1891 |
-
st.write("Document Content Extracted:", doc_content)
|
| 1892 |
|
| 1893 |
# Generate AI response using document context
|
| 1894 |
full_prompt = f"Document Content:\n{doc_content}\n\nUser Query: {query}\n\nResponse:"
|
| 1895 |
try:
|
| 1896 |
-
llm = ChatOpenAI(model="gpt-
|
| 1897 |
response = llm.invoke(full_prompt)
|
| 1898 |
return response.content
|
| 1899 |
except Exception as e:
|
|
|
|
| 1878 |
# Extract document name from the query
|
| 1879 |
doc_name_match = re.search(r"[\"']?([^\"']+\.(pdf|docx|doc|txt))[\"']?", query, re.IGNORECASE)
|
| 1880 |
doc_name = doc_name_match.group(1) if doc_name_match else None
|
| 1881 |
+
st.sidebar.write("Extracted Document Name:", doc_name) # Debugging log
|
| 1882 |
+
|
| 1883 |
if not doc_name:
|
| 1884 |
return "Please specify a document name in your query."
|
| 1885 |
|
|
|
|
| 1890 |
if error:
|
| 1891 |
return error
|
| 1892 |
|
| 1893 |
+
st.sidebar.write("Document Content Extracted:", doc_content)
|
| 1894 |
|
| 1895 |
# Generate AI response using document context
|
| 1896 |
full_prompt = f"Document Content:\n{doc_content}\n\nUser Query: {query}\n\nResponse:"
|
| 1897 |
try:
|
| 1898 |
+
llm = ChatOpenAI(model="gpt-4o", temperature=0.5, api_key=openai_api_key)
|
| 1899 |
response = llm.invoke(full_prompt)
|
| 1900 |
return response.content
|
| 1901 |
except Exception as e:
|