Update app.py
Browse files
app.py
CHANGED
@@ -115,7 +115,7 @@ class DetailedExplainer:
|
|
115 |
)
|
116 |
result = self.explainer(
|
117 |
prompt,
|
118 |
-
|
119 |
min_length=80,
|
120 |
do_sample=False
|
121 |
)
|
@@ -125,8 +125,15 @@ class DetailedExplainer:
|
|
125 |
concepts = self.extract_concepts(text)
|
126 |
explanations = {}
|
127 |
for concept in concepts:
|
128 |
-
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
class AdvancedPDFAnalyzer:
|
132 |
def __init__(self):
|
@@ -231,14 +238,25 @@ def ask_question_gradio(question: str):
|
|
231 |
result = analyzer.answer_question(question, documents)
|
232 |
answer = result['answer']
|
233 |
confidence = result['confidence']
|
234 |
-
explanation = "\n\n".join(
|
235 |
-
f"πΉ {concept}: {desc}"
|
236 |
-
for concept, desc in result.get("explanations", {}).get("explanations", {}).items()
|
237 |
-
)
|
238 |
-
return f"π **Answer**: {answer}\n\nπ **Confidence**: {confidence:.2f}\n\nπ **Explanations**:\n{explanation}"
|
239 |
-
except Exception as e:
|
240 |
-
return f"β Error: {str(e)}"
|
241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
|
243 |
demo = gr.Interface(
|
244 |
fn=ask_question_gradio,
|
@@ -248,4 +266,4 @@ demo = gr.Interface(
|
|
248 |
description="Ask a question based on the document loaded in this system."
|
249 |
)
|
250 |
|
251 |
-
demo.launch()
|
|
|
115 |
)
|
116 |
result = self.explainer(
|
117 |
prompt,
|
118 |
+
max_new_tokens=800,
|
119 |
min_length=80,
|
120 |
do_sample=False
|
121 |
)
|
|
|
125 |
concepts = self.extract_concepts(text)
|
126 |
explanations = {}
|
127 |
for concept in concepts:
|
128 |
+
try:
|
129 |
+
explanations[concept] = self.explain_concept(concept, context)
|
130 |
+
except Exception as e:
|
131 |
+
explanations[concept] = f"[Error explaining concept: {e}]"
|
132 |
+
return {
|
133 |
+
"answer_sentence": text.strip(),
|
134 |
+
"concepts": concepts,
|
135 |
+
"explanations": explanations
|
136 |
+
}
|
137 |
|
138 |
class AdvancedPDFAnalyzer:
|
139 |
def __init__(self):
|
|
|
238 |
result = analyzer.answer_question(question, documents)
|
239 |
answer = result['answer']
|
240 |
confidence = result['confidence']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
|
242 |
+
explanation_data = result.get("explanations", {})
|
243 |
+
answer_sentence = explanation_data.get("answer_sentence", answer)
|
244 |
+
explanations = explanation_data.get("explanations", {})
|
245 |
+
|
246 |
+
markdown_output = f"\U0001F4CC **Answer:**\n{answer_sentence}\n\n"
|
247 |
+
markdown_output += f"\U0001F512 **Confidence:** {confidence:.2f}\n\n"
|
248 |
+
markdown_output += f"\U0001F4D8 **Concept Explanations:**\n"
|
249 |
+
|
250 |
+
if not explanations:
|
251 |
+
markdown_output += "\nNo key concepts found to explain."
|
252 |
+
else:
|
253 |
+
for concept, desc in explanations.items():
|
254 |
+
markdown_output += f"\n\U0001F539 **{concept}**\n{desc}\n"
|
255 |
+
|
256 |
+
return markdown_output
|
257 |
+
|
258 |
+
except Exception as e:
|
259 |
+
return f"\u274C Error: {str(e)}"
|
260 |
|
261 |
demo = gr.Interface(
|
262 |
fn=ask_question_gradio,
|
|
|
266 |
description="Ask a question based on the document loaded in this system."
|
267 |
)
|
268 |
|
269 |
+
demo.launch()
|