Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,9 @@ import torchvision
|
|
7 |
import nltk
|
8 |
import torch
|
9 |
import pandas as pd
|
|
|
10 |
import requests
|
|
|
11 |
import zipfile
|
12 |
import tempfile
|
13 |
from PyPDF2 import PdfReader
|
@@ -34,6 +36,14 @@ from safetensors.torch import safe_open
|
|
34 |
nltk.download('punkt_tab')
|
35 |
|
36 |
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
app.add_middleware(
|
38 |
CORSMiddleware,
|
39 |
allow_origins=["*"],
|
@@ -652,3 +662,66 @@ if not init_success:
|
|
652 |
if __name__ == "__main__":
|
653 |
import uvicorn
|
654 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
import nltk
|
8 |
import torch
|
9 |
import pandas as pd
|
10 |
+
import streamlit as st
|
11 |
import requests
|
12 |
+
import threading
|
13 |
import zipfile
|
14 |
import tempfile
|
15 |
from PyPDF2 import PdfReader
|
|
|
36 |
nltk.download('punkt_tab')
|
37 |
|
38 |
app = FastAPI()
|
39 |
+
|
40 |
+
with open("style.css") as f:
|
41 |
+
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
|
42 |
+
# Streamlit interface
|
43 |
+
def start_streamlit():
|
44 |
+
st.title("My Hugging Face App")
|
45 |
+
st.text_input("Ask a question:")
|
46 |
+
|
47 |
app.add_middleware(
|
48 |
CORSMiddleware,
|
49 |
allow_origins=["*"],
|
|
|
662 |
if __name__ == "__main__":
|
663 |
import uvicorn
|
664 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
665 |
+
|
666 |
+
# Chat API
|
667 |
+
st.header("Chat API")
|
668 |
+
chat_query = st.text_input("Enter your chat query:")
|
669 |
+
language_code = st.selectbox("Select language", ["English", "Arabic"])
|
670 |
+
|
671 |
+
if st.button("Submit Chat Query"):
|
672 |
+
response = requests.post(f"{BASE_URL}/api/chat", json={
|
673 |
+
"query": chat_query,
|
674 |
+
"language_code": 0 if language_code == "Arabic" else 1
|
675 |
+
})
|
676 |
+
if response.status_code == 200:
|
677 |
+
st.success("Response: " + response.json()['response'])
|
678 |
+
else:
|
679 |
+
st.error(f"Error: {response.status_code} - {response.text}")
|
680 |
+
|
681 |
+
# Resources API
|
682 |
+
st.header("Resources API")
|
683 |
+
conditions = st.text_input("Enter medical conditions:")
|
684 |
+
daily_symptoms = st.text_area("Enter daily symptoms:")
|
685 |
+
count = st.number_input("Number of resources", min_value=1, max_value=10, value=5)
|
686 |
+
|
687 |
+
if st.button("Submit Resources Query"):
|
688 |
+
response = requests.post(f"{BASE_URL}/api/resources", json={
|
689 |
+
"conditions": conditions,
|
690 |
+
"daily_symptoms": daily_symptoms,
|
691 |
+
"count": count
|
692 |
+
})
|
693 |
+
if response.status_code == 200:
|
694 |
+
resources = response.json()
|
695 |
+
st.write("Relevant Resources:")
|
696 |
+
for resource in resources:
|
697 |
+
st.markdown(f"- **{resource['title']}**: [Link]({resource['url']})")
|
698 |
+
else:
|
699 |
+
st.error(f"Error: {response.status_code} - {response.text}")
|
700 |
+
|
701 |
+
# Recipes API
|
702 |
+
st.header("Recipes API")
|
703 |
+
recipe_conditions = st.text_input("Enter conditions for recipes:")
|
704 |
+
recipe_symptoms = st.text_area("Enter symptoms for recipes:")
|
705 |
+
recipe_count = st.number_input("Number of recipes", min_value=1, max_value=10, value=5)
|
706 |
+
|
707 |
+
if st.button("Submit Recipes Query"):
|
708 |
+
response = requests.post(f"{BASE_URL}/api/recipes", json={
|
709 |
+
"conditions": recipe_conditions,
|
710 |
+
"daily_symptoms": recipe_symptoms,
|
711 |
+
"count": recipe_count
|
712 |
+
})
|
713 |
+
if response.status_code == 200:
|
714 |
+
recipes = response.json()['recipes']
|
715 |
+
st.write("Relevant Recipes:")
|
716 |
+
for recipe in recipes:
|
717 |
+
st.markdown(f"- **{recipe['title']}**: [Link]({recipe['url']})")
|
718 |
+
else:
|
719 |
+
st.error(f"Error: {response.status_code} - {response.text}")
|
720 |
+
if __name__ == "__main__":
|
721 |
+
# Start FastAPI in a background thread
|
722 |
+
fastapi_thread = threading.Thread(target=run_fastapi)
|
723 |
+
fastapi_thread.start()
|
724 |
+
|
725 |
+
# Start Streamlit
|
726 |
+
start_streamlit()
|
727 |
+
|