thechaiexperiment commited on
Commit
cc5539d
·
verified ·
1 Parent(s): 00e0962

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -246
app.py CHANGED
@@ -503,253 +503,9 @@ def translate_en_to_ar(text):
503
  print(f"Error during English to Arabic translation: {e}")
504
  return None
505
 
506
- @app.get("/", response_class=HTMLResponse)
507
  async def root():
508
- return """
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
- /* Spinner styles */
590
- .spinner {
591
- border: 4px solid #f3f3f3;
592
- border-top: 4px solid #3498db;
593
- border-radius: 50%;
594
- width: 50px;
595
- height: 50px;
596
- animation: spin 2s linear infinite;
597
- margin: 20px auto;
598
- }
599
-
600
- @keyframes spin {
601
- 0% { transform: rotate(0deg); }
602
- 100% { transform: rotate(360deg); }
603
- }
604
- </style>
605
- </head>
606
- <body>
607
- <header>
608
- <h1>AI Medical Assistance Hub</h1>
609
- <p>Empowering better health decisions with AI</p>
610
- </header>
611
- <div id="updates">
612
- <strong>Updates:</strong> This space can be used for announcements or user guidance!
613
- </div>
614
- <div class="container">
615
- <!-- Input Section -->
616
- <div class="input-section">
617
- <h2>Input Section</h2>
618
- <label>Chronic Conditions:</label>
619
- <input type="text" id="conditions" placeholder="Enter conditions (comma-separated)">
620
- <label>Daily Symptoms:</label>
621
- <input type="text" id="symptoms" placeholder="Enter symptoms (comma-separated)">
622
- <label>Mental Health Conditions:</label>
623
- <input type="text" id="mental_health" placeholder="Enter mental health conditions (comma-separated)">
624
- <label>Language:</label>
625
- <select id="language">
626
- <option value="1">English</option>
627
- <option value="0">Arabic</option>
628
- </select>
629
- <label>Number of Articles:</label>
630
- <input type="number" id="count" placeholder="Number of articles to retrieve">
631
- <label>Medical Question:</label>
632
- <textarea id="question" rows="4" placeholder="Type your medical question here"></textarea>
633
-
634
- <!-- Separate buttons -->
635
- <button onclick="submitChat()">Submit Chat</button>
636
- <button onclick="submitResources()">Submit Resources</button>
637
- <button onclick="submitRecipes()">Submit Recipes</button>
638
- </div>
639
- <!-- Output Section -->
640
- <div class="output-section">
641
- <h2>Output Section</h2>
642
- <div class="output-card">
643
- <h3>Chat Response</h3>
644
- <p id="chat_output">No response yet...</p>
645
- </div>
646
- <div class="output-card">
647
- <h3>Resources</h3>
648
- <p id="resources_output">No resources yet...</p>
649
- </div>
650
- <div class="output-card">
651
- <h3>Recipes</h3>
652
- <p id="recipes_output">No recipes yet...</p>
653
- </div>
654
- </div>
655
- </div>
656
- <footer>
657
- <p>&copy; 2025 AI Medical Assistance Hub | <a href="#">GitHub</a> | <a href="#">Hugging Face</a></p>
658
- </footer>
659
- <script>
660
- // Show a loading spinner
661
- function showLoading(show) {
662
- const spinner = document.getElementById('loading');
663
- if (show) {
664
- spinner.style.display = 'block';
665
- } else {
666
- spinner.style.display = 'none';
667
- }
668
- }
669
-
670
- async function submitChat() {
671
- showLoading(true);
672
- const question = document.getElementById('question').value;
673
- const language = document.getElementById('language').value;
674
-
675
- try {
676
- const chatResponse = await fetch('/api/chat', {
677
- method: 'POST',
678
- headers: { 'Content-Type': 'application/json' },
679
- body: JSON.stringify({ query: question, language_code: language })
680
- });
681
- const chatData = await chatResponse.json();
682
- document.getElementById('chat_output').textContent = chatData.response;
683
- } catch (error) {
684
- console.error('Error submitting chat data:', error);
685
- } finally {
686
- showLoading(false);
687
- }
688
- }
689
-
690
- async function submitResources() {
691
- showLoading(true);
692
- const profile = {
693
- conditions: document.getElementById('conditions').value,
694
- daily_symptoms: document.getElementById('symptoms').value,
695
- mental_health: document.getElementById('mental_health').value,
696
- language_code: document.getElementById('language').value,
697
- count: document.getElementById('count').value
698
- };
699
-
700
- try {
701
- const resourcesResponse = await fetch('/api/resources', {
702
- method: 'POST',
703
- headers: { 'Content-Type': 'application/json' },
704
- body: JSON.stringify(profile)
705
- });
706
- const resourcesData = await resourcesResponse.json();
707
- let output = '';
708
- resourcesData.forEach(item => {
709
- output += `${item.title}: ${item.url}\n`;
710
- });
711
- document.getElementById('resources_output').textContent = output;
712
- } catch (error) {
713
- console.error('Error submitting resources data:', error);
714
- } finally {
715
- showLoading(false);
716
- }
717
- }
718
-
719
- async function submitRecipes() {
720
- showLoading(true);
721
- const profile = {
722
- conditions: document.getElementById('conditions').value,
723
- daily_symptoms: document.getElementById('symptoms').value,
724
- mental_health: document.getElementById('mental_health').value,
725
- language_code: document.getElementById('language').value,
726
- count: document.getElementById('count').value
727
- };
728
-
729
- try {
730
- const recipesResponse = await fetch('/api/recipes', {
731
- method: 'POST',
732
- headers: { 'Content-Type': 'application/json' },
733
- body: JSON.stringify(profile)
734
- });
735
- const recipesData = await recipesResponse.json();
736
- let output = '';
737
- recipesData.forEach(item => {
738
- output += `${item.title}: ${item.url}\n`;
739
- });
740
- document.getElementById('recipes_output').textContent = output;
741
- } catch (error) {
742
- console.error('Error submitting recipes data:', error);
743
- } finally {
744
- showLoading(false);
745
- }
746
- }
747
- </script>
748
- <div id="loading" class="spinner" style="display:none;"></div>
749
- </body>
750
- </html>
751
- """
752
-
753
 
754
 
755
 
 
503
  print(f"Error during English to Arabic translation: {e}")
504
  return None
505
 
506
+ @app.get("/")
507
  async def root():
508
+ return {"message": "Welcome to the FastAPI application! Use the /health endpoint to check health, and /api/query for processing queries."}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
509
 
510
 
511