Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -509,94 +509,140 @@ async def root():
|
|
| 509 |
<!DOCTYPE html>
|
| 510 |
<html>
|
| 511 |
<head>
|
| 512 |
-
<title>
|
| 513 |
<style>
|
| 514 |
body {
|
| 515 |
-
font-family: Arial, sans-serif;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 516 |
margin: 20px;
|
| 517 |
-
|
|
|
|
|
|
|
| 518 |
}
|
| 519 |
.container {
|
| 520 |
-
|
| 521 |
-
|
|
|
|
| 522 |
padding: 20px;
|
| 523 |
-
background: white;
|
| 524 |
-
border-radius: 8px;
|
| 525 |
-
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
|
| 526 |
-
}
|
| 527 |
-
h1 {
|
| 528 |
-
color: #333;
|
| 529 |
-
text-align: center;
|
| 530 |
}
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
|
|
|
|
|
|
| 535 |
}
|
| 536 |
-
input, select,
|
| 537 |
width: 100%;
|
| 538 |
padding: 10px;
|
| 539 |
-
margin
|
| 540 |
-
border: 1px solid #
|
| 541 |
border-radius: 5px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 542 |
}
|
| 543 |
-
|
| 544 |
-
background-color: #
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
|
|
|
|
|
|
|
|
|
| 548 |
}
|
| 549 |
-
|
| 550 |
-
|
|
|
|
|
|
|
|
|
|
| 551 |
}
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
margin-top: 20px;
|
| 557 |
}
|
| 558 |
</style>
|
| 559 |
</head>
|
| 560 |
<body>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 561 |
<div class="container">
|
| 562 |
-
|
| 563 |
-
<
|
| 564 |
-
<
|
| 565 |
-
<
|
| 566 |
-
|
| 567 |
-
<label
|
| 568 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
| 569 |
<option value="1">English</option>
|
| 570 |
<option value="0">Arabic</option>
|
| 571 |
</select>
|
| 572 |
-
|
| 573 |
-
<
|
| 574 |
-
|
| 575 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 576 |
</div>
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
const query = document.getElementById('query').value;
|
| 581 |
-
const language = document.getElementById('language').value;
|
| 582 |
-
|
| 583 |
-
const response = await fetch('/api/chat', {
|
| 584 |
-
method: 'POST',
|
| 585 |
-
headers: {
|
| 586 |
-
'Content-Type': 'application/json',
|
| 587 |
-
},
|
| 588 |
-
body: JSON.stringify({ query, language_code: parseInt(language) }),
|
| 589 |
-
});
|
| 590 |
-
|
| 591 |
-
const result = await response.json();
|
| 592 |
-
document.getElementById('responseOutput').innerText = result.response || 'No response';
|
| 593 |
-
}
|
| 594 |
-
</script>
|
| 595 |
</body>
|
| 596 |
</html>
|
| 597 |
"""
|
| 598 |
|
| 599 |
|
|
|
|
| 600 |
@app.get("/health")
|
| 601 |
async def health_check():
|
| 602 |
"""Health check endpoint"""
|
|
@@ -723,18 +769,16 @@ async def recipes_endpoint(profile: MedicalProfile):
|
|
| 723 |
metadata_path = 'recipes_metadata.xlsx'
|
| 724 |
metadata = retrieve_metadata(document_indices, metadata_path=metadata_path)
|
| 725 |
print(f"Retrieved Metadata: {metadata}")
|
| 726 |
-
# Convert metadata dictionary to a list of recipe objects
|
| 727 |
recipes = []
|
| 728 |
for item in metadata.values():
|
| 729 |
recipes.append({
|
| 730 |
"title": item["original_file_name"] if "original_file_name" in item else "Unknown Title",
|
| 731 |
"url": item["url"] if "url" in item else ""
|
| 732 |
-
})
|
| 733 |
-
|
| 734 |
response = {
|
| 735 |
-
"recipes": recipes
|
| 736 |
}
|
| 737 |
-
|
| 738 |
return response
|
| 739 |
except ValueError as ve:
|
| 740 |
raise HTTPException(status_code=400, detail=str(ve))
|
|
|
|
| 509 |
<!DOCTYPE html>
|
| 510 |
<html>
|
| 511 |
<head>
|
| 512 |
+
<title>AI Medical Assistance Hub</title>
|
| 513 |
<style>
|
| 514 |
body {
|
| 515 |
+
font-family: 'Arial', sans-serif;
|
| 516 |
+
background-color: #121212;
|
| 517 |
+
color: #ffffff;
|
| 518 |
+
margin: 0;
|
| 519 |
+
padding: 0;
|
| 520 |
+
}
|
| 521 |
+
header {
|
| 522 |
+
background-color: #1e1e1e;
|
| 523 |
+
padding: 20px;
|
| 524 |
+
text-align: center;
|
| 525 |
+
border-bottom: 2px solid #444;
|
| 526 |
+
}
|
| 527 |
+
header h1 {
|
| 528 |
+
font-size: 2.5em;
|
| 529 |
+
margin: 0;
|
| 530 |
+
}
|
| 531 |
+
header p {
|
| 532 |
+
font-size: 1.2em;
|
| 533 |
+
color: #aaaaaa;
|
| 534 |
+
}
|
| 535 |
+
#updates {
|
| 536 |
+
background-color: #1e1e1e;
|
| 537 |
margin: 20px;
|
| 538 |
+
padding: 15px;
|
| 539 |
+
border-radius: 10px;
|
| 540 |
+
border: 1px solid #444;
|
| 541 |
}
|
| 542 |
.container {
|
| 543 |
+
display: flex;
|
| 544 |
+
flex-direction: row;
|
| 545 |
+
gap: 20px;
|
| 546 |
padding: 20px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 547 |
}
|
| 548 |
+
.input-section, .output-section {
|
| 549 |
+
flex: 1;
|
| 550 |
+
background-color: #1e1e1e;
|
| 551 |
+
padding: 20px;
|
| 552 |
+
border-radius: 10px;
|
| 553 |
+
border: 1px solid #444;
|
| 554 |
}
|
| 555 |
+
.input-section input, .input-section select, .input-section textarea {
|
| 556 |
width: 100%;
|
| 557 |
padding: 10px;
|
| 558 |
+
margin: 10px 0;
|
| 559 |
+
border: 1px solid #444;
|
| 560 |
border-radius: 5px;
|
| 561 |
+
background-color: #2c2c2c;
|
| 562 |
+
color: #ffffff;
|
| 563 |
+
}
|
| 564 |
+
.output-section {
|
| 565 |
+
display: flex;
|
| 566 |
+
flex-direction: column;
|
| 567 |
+
gap: 20px;
|
| 568 |
}
|
| 569 |
+
.output-card {
|
| 570 |
+
background-color: #292929;
|
| 571 |
+
padding: 20px;
|
| 572 |
+
border-radius: 10px;
|
| 573 |
+
border: 1px solid #444;
|
| 574 |
+
}
|
| 575 |
+
.output-card h3 {
|
| 576 |
+
margin-top: 0;
|
| 577 |
}
|
| 578 |
+
footer {
|
| 579 |
+
text-align: center;
|
| 580 |
+
background-color: #1e1e1e;
|
| 581 |
+
padding: 15px;
|
| 582 |
+
border-top: 2px solid #444;
|
| 583 |
}
|
| 584 |
+
footer a {
|
| 585 |
+
color: #50b7f5;
|
| 586 |
+
text-decoration: none;
|
| 587 |
+
margin: 0 10px;
|
|
|
|
| 588 |
}
|
| 589 |
</style>
|
| 590 |
</head>
|
| 591 |
<body>
|
| 592 |
+
<header>
|
| 593 |
+
<h1>AI Medical Assistance Hub</h1>
|
| 594 |
+
<p>Empowering better health decisions with AI</p>
|
| 595 |
+
</header>
|
| 596 |
+
<div id="updates">
|
| 597 |
+
<strong>Updates:</strong> This space can be used for announcements or user guidance!
|
| 598 |
+
</div>
|
| 599 |
<div class="container">
|
| 600 |
+
<!-- Input Section -->
|
| 601 |
+
<div class="input-section">
|
| 602 |
+
<h2>Input Section</h2>
|
| 603 |
+
<label>Chronic Conditions:</label>
|
| 604 |
+
<input type="text" id="conditions" placeholder="Enter conditions (comma-separated)">
|
| 605 |
+
<label>Daily Symptoms:</label>
|
| 606 |
+
<input type="text" id="symptoms" placeholder="Enter symptoms (comma-separated)">
|
| 607 |
+
<label>Mental Health Conditions:</label>
|
| 608 |
+
<input type="text" id="mental_health" placeholder="Enter mental health conditions (comma-separated)">
|
| 609 |
+
<label>Language:</label>
|
| 610 |
+
<select id="language">
|
| 611 |
<option value="1">English</option>
|
| 612 |
<option value="0">Arabic</option>
|
| 613 |
</select>
|
| 614 |
+
<label>Number of Articles:</label>
|
| 615 |
+
<input type="number" id="count" placeholder="Number of articles to retrieve">
|
| 616 |
+
<label>Medical Question:</label>
|
| 617 |
+
<textarea id="question" rows="4" placeholder="Type your medical question here"></textarea>
|
| 618 |
+
<button onclick="submitData()">Submit</button>
|
| 619 |
+
</div>
|
| 620 |
+
<!-- Output Section -->
|
| 621 |
+
<div class="output-section">
|
| 622 |
+
<h2>Output Section</h2>
|
| 623 |
+
<div class="output-card">
|
| 624 |
+
<h3>Chat Response</h3>
|
| 625 |
+
<p id="chat_output">No response yet...</p>
|
| 626 |
+
</div>
|
| 627 |
+
<div class="output-card">
|
| 628 |
+
<h3>Resources</h3>
|
| 629 |
+
<p id="resources_output">No resources yet...</p>
|
| 630 |
+
</div>
|
| 631 |
+
<div class="output-card">
|
| 632 |
+
<h3>Recipes</h3>
|
| 633 |
+
<p id="recipes_output">No recipes yet...</p>
|
| 634 |
+
</div>
|
| 635 |
+
</div>
|
| 636 |
</div>
|
| 637 |
+
<footer>
|
| 638 |
+
<p>© 2025 AI Medical Assistance Hub | <a href="#">GitHub</a> | <a href="#">Hugging Face</a></p>
|
| 639 |
+
</footer>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 640 |
</body>
|
| 641 |
</html>
|
| 642 |
"""
|
| 643 |
|
| 644 |
|
| 645 |
+
|
| 646 |
@app.get("/health")
|
| 647 |
async def health_check():
|
| 648 |
"""Health check endpoint"""
|
|
|
|
| 769 |
metadata_path = 'recipes_metadata.xlsx'
|
| 770 |
metadata = retrieve_metadata(document_indices, metadata_path=metadata_path)
|
| 771 |
print(f"Retrieved Metadata: {metadata}")
|
|
|
|
| 772 |
recipes = []
|
| 773 |
for item in metadata.values():
|
| 774 |
recipes.append({
|
| 775 |
"title": item["original_file_name"] if "original_file_name" in item else "Unknown Title",
|
| 776 |
"url": item["url"] if "url" in item else ""
|
| 777 |
+
})
|
|
|
|
| 778 |
response = {
|
| 779 |
+
"recipes": recipes
|
| 780 |
}
|
| 781 |
+
print response
|
| 782 |
return response
|
| 783 |
except ValueError as ve:
|
| 784 |
raise HTTPException(status_code=400, detail=str(ve))
|