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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -35
app.py CHANGED
@@ -586,6 +586,21 @@ async def root():
586
  text-decoration: none;
587
  margin: 0 10px;
588
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
589
  </style>
590
  </head>
591
  <body>
@@ -615,7 +630,11 @@ async def root():
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">
@@ -638,69 +657,102 @@ async def root():
638
  <p>&copy; 2025 AI Medical Assistance Hub | <a href="#">GitHub</a> | <a href="#">Hugging Face</a></p>
639
  </footer>
640
  <script>
641
- async function submitData() {
642
- // Get input values
643
- const conditions = document.getElementById('conditions').value;
644
- const symptoms = document.getElementById('symptoms').value;
645
- const mental_health = document.getElementById('mental_health').value;
646
- const language = document.getElementById('language').value;
647
- const count = document.getElementById('count').value;
 
 
 
 
 
648
  const question = document.getElementById('question').value;
649
-
650
- // Construct the profile object
651
- const profile = {
652
- conditions: conditions,
653
- daily_symptoms: symptoms,
654
- mental_health: mental_health,
655
- language_code: language,
656
- count: count
657
- };
658
 
659
  try {
660
- // Send request to /api/chat endpoint
661
  const chatResponse = await fetch('/api/chat', {
662
  method: 'POST',
663
- headers: {
664
- 'Content-Type': 'application/json',
665
- },
666
  body: JSON.stringify({ query: question, language_code: language })
667
  });
668
  const chatData = await chatResponse.json();
669
  document.getElementById('chat_output').textContent = chatData.response;
670
-
671
- // Send request to /api/resources endpoint
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
672
  const resourcesResponse = await fetch('/api/resources', {
673
  method: 'POST',
674
- headers: {
675
- 'Content-Type': 'application/json',
676
- },
677
  body: JSON.stringify(profile)
678
  });
679
  const resourcesData = await resourcesResponse.json();
680
- document.getElementById('resources_output').textContent = JSON.stringify(resourcesData, null, 2);
681
-
682
- // Send request to /api/recipes endpoint
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
683
  const recipesResponse = await fetch('/api/recipes', {
684
  method: 'POST',
685
- headers: {
686
- 'Content-Type': 'application/json',
687
- },
688
  body: JSON.stringify(profile)
689
  });
690
  const recipesData = await recipesResponse.json();
691
- document.getElementById('recipes_output').textContent = JSON.stringify(recipesData, null, 2);
692
-
 
 
 
693
  } catch (error) {
694
- console.error('Error submitting data:', error);
 
 
695
  }
696
  }
697
  </script>
 
698
  </body>
699
  </html>
700
  """
701
 
702
 
703
 
 
704
  @app.get("/health")
705
  async def health_check():
706
  """Health check endpoint"""
 
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>
 
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">
 
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
+
756
  @app.get("/health")
757
  async def health_check():
758
  """Health check endpoint"""