Spaces:
Build error
Build error
Commit
·
162cda9
1
Parent(s):
774c50b
Fix: Correct dataset field mapping for question/answer extraction
Browse files- app_gradio.py +10 -5
app_gradio.py
CHANGED
|
@@ -75,7 +75,8 @@ class TextilindoAI:
|
|
| 75 |
similarities = []
|
| 76 |
|
| 77 |
for example in self.dataset:
|
| 78 |
-
|
|
|
|
| 79 |
similarity = SequenceMatcher(None, query.lower(), question).ratio()
|
| 80 |
similarities.append((similarity, example))
|
| 81 |
|
|
@@ -92,8 +93,9 @@ class TextilindoAI:
|
|
| 92 |
# Build context from similar examples
|
| 93 |
context = ""
|
| 94 |
for example in similar_examples:
|
| 95 |
-
|
| 96 |
-
|
|
|
|
| 97 |
context += f"Q: {question}\nA: {answer}\n\n"
|
| 98 |
|
| 99 |
# Create prompt
|
|
@@ -109,8 +111,11 @@ Please provide a helpful response based on the context above. If the context doe
|
|
| 109 |
# For now, return a simple response based on context
|
| 110 |
if similar_examples:
|
| 111 |
# Return the most similar answer
|
| 112 |
-
best_answer = similar_examples[0].get('answer', '')
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
| 114 |
else:
|
| 115 |
return "I'm sorry, I don't have specific information about that. Please contact Textilindo directly for more details."
|
| 116 |
|
|
|
|
| 75 |
similarities = []
|
| 76 |
|
| 77 |
for example in self.dataset:
|
| 78 |
+
# Try different field names that might exist in the dataset
|
| 79 |
+
question = example.get('question', example.get('instruction', '')).lower()
|
| 80 |
similarity = SequenceMatcher(None, query.lower(), question).ratio()
|
| 81 |
similarities.append((similarity, example))
|
| 82 |
|
|
|
|
| 93 |
# Build context from similar examples
|
| 94 |
context = ""
|
| 95 |
for example in similar_examples:
|
| 96 |
+
# Try different field names that might exist in the dataset
|
| 97 |
+
question = example.get('question', example.get('instruction', ''))
|
| 98 |
+
answer = example.get('answer', example.get('output', ''))
|
| 99 |
context += f"Q: {question}\nA: {answer}\n\n"
|
| 100 |
|
| 101 |
# Create prompt
|
|
|
|
| 111 |
# For now, return a simple response based on context
|
| 112 |
if similar_examples:
|
| 113 |
# Return the most similar answer
|
| 114 |
+
best_answer = similar_examples[0].get('answer', similar_examples[0].get('output', ''))
|
| 115 |
+
if best_answer:
|
| 116 |
+
return f"Based on our knowledge base: {best_answer}"
|
| 117 |
+
else:
|
| 118 |
+
return "I found some relevant information but couldn't extract a proper answer. Please try rephrasing your question."
|
| 119 |
else:
|
| 120 |
return "I'm sorry, I don't have specific information about that. Please contact Textilindo directly for more details."
|
| 121 |
|