Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -49,14 +49,44 @@ if query and dataset:
|
|
49 |
# Search in the vector database for the closest matches
|
50 |
distances, indices = index.search(query_embedding, k=1) # Limit to the top 1 result
|
51 |
|
|
|
|
|
|
|
52 |
# Retrieve the most relevant context from the metadata
|
53 |
retrieved_context = metadata[indices[0][0]] # Get the top 1 context
|
54 |
|
|
|
|
|
|
|
55 |
# Extract the most relevant part of the context
|
56 |
relevant_context = extract_relevant_context(retrieved_context)
|
57 |
|
|
|
|
|
|
|
58 |
# Construct a concise prompt
|
59 |
prompt = f"Context: {relevant_context}\n\nQuery: {query}\n\nAnswer concisely:"
|
|
|
|
|
|
|
|
|
60 |
result = query_huggingface_model(prompt)
|
61 |
|
62 |
-
# Handling the list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
# Search in the vector database for the closest matches
|
50 |
distances, indices = index.search(query_embedding, k=1) # Limit to the top 1 result
|
51 |
|
52 |
+
# Debug: Display the index search results
|
53 |
+
st.write("Debug: Index search results:", indices, distances)
|
54 |
+
|
55 |
# Retrieve the most relevant context from the metadata
|
56 |
retrieved_context = metadata[indices[0][0]] # Get the top 1 context
|
57 |
|
58 |
+
# Debug: Display the retrieved context
|
59 |
+
st.write("Debug: Retrieved context:", retrieved_context)
|
60 |
+
|
61 |
# Extract the most relevant part of the context
|
62 |
relevant_context = extract_relevant_context(retrieved_context)
|
63 |
|
64 |
+
# Debug: Display the relevant context
|
65 |
+
st.write("Debug: Relevant context used in prompt:", relevant_context)
|
66 |
+
|
67 |
# Construct a concise prompt
|
68 |
prompt = f"Context: {relevant_context}\n\nQuery: {query}\n\nAnswer concisely:"
|
69 |
+
|
70 |
+
# Debug: Display the final prompt
|
71 |
+
st.write("Debug: Prompt sent to model:", prompt)
|
72 |
+
|
73 |
result = query_huggingface_model(prompt)
|
74 |
|
75 |
+
# Handling the list result and clean up output
|
76 |
+
if isinstance(result, list) and len(result) > 0:
|
77 |
+
generated_text = result[0].get("generated_text", "No response from model")
|
78 |
+
|
79 |
+
# Debug: Display the generated text from the model
|
80 |
+
st.write("Debug: Generated text from model:", generated_text)
|
81 |
+
|
82 |
+
# Format the output to show only the query and the answer
|
83 |
+
final_output = format_response(query, generated_text.strip())
|
84 |
+
|
85 |
+
# Display the final formatted output
|
86 |
+
st.write("Chatbot:", final_output)
|
87 |
+
else:
|
88 |
+
st.write("Chatbot: No response from model or error occurred")
|
89 |
+
else:
|
90 |
+
st.write("Vector database or metadata not found for the selected dataset.")
|
91 |
+
else:
|
92 |
+
st.write("Access denied: You do not have permission to access this dataset.")
|