Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
import os
|
4 |
+
|
5 |
+
# Initialize the Hugging Face pipeline with the desired model
|
6 |
+
model = "Bio-Medical-MultiModal-Llama-3-8B-V1" # Replace with actual model name from Hugging Face
|
7 |
+
diagnosis_pipeline = pipeline("text-generation", model=model)
|
8 |
+
|
9 |
+
# Function to get medical diagnosis using the model
|
10 |
+
def get_medical_response(patient_name, age, sex, symptoms, xray_mri=None, medical_reports=None):
|
11 |
+
# Prepare the input message with the provided patient details
|
12 |
+
message_content = f"Patient Details:\nName: {patient_name}\nAge: {age}\nSex: {sex}\nSymptoms: {symptoms}"
|
13 |
+
|
14 |
+
# If X-ray/MRI file is provided, include it
|
15 |
+
if xray_mri:
|
16 |
+
message_content += f"\nX-ray/MRI: {xray_mri}" # File path or additional info
|
17 |
+
|
18 |
+
# If medical reports file is provided, include it
|
19 |
+
if medical_reports:
|
20 |
+
message_content += f"\nMedical Reports: {medical_reports}" # File path or additional info
|
21 |
+
|
22 |
+
# Use the Hugging Face model to generate a diagnosis response
|
23 |
+
try:
|
24 |
+
result = diagnosis_pipeline(message_content, max_length=300)
|
25 |
+
return result[0]['generated_text']
|
26 |
+
except Exception as e:
|
27 |
+
return f"Error: {str(e)}" # Return the error message if something goes wrong
|
28 |
+
|
29 |
+
# Streamlit UI
|
30 |
+
def main():
|
31 |
+
st.title("Medical Diagnosis Assistant")
|
32 |
+
|
33 |
+
# Collect patient details
|
34 |
+
patient_name = st.text_input("Patient Name")
|
35 |
+
age = st.number_input("Age", min_value=0)
|
36 |
+
sex = st.radio("Sex", options=["Male", "Female", "Other"])
|
37 |
+
symptoms = st.text_area("Medical Symptoms")
|
38 |
+
|
39 |
+
# Optional file inputs
|
40 |
+
xray_mri = st.file_uploader("Upload X-ray/MRI Image (Optional)", type=["jpg", "jpeg", "png", "dcm", "pdf"])
|
41 |
+
medical_reports = st.file_uploader("Upload Medical Reports (Optional)", type=["pdf", "txt", "docx"])
|
42 |
+
|
43 |
+
if st.button("Submit"):
|
44 |
+
# Get medical diagnosis using the model
|
45 |
+
diagnosis = get_medical_response(patient_name, age, sex, symptoms, xray_mri.name if xray_mri else None, medical_reports.name if medical_reports else None)
|
46 |
+
|
47 |
+
# Display the response
|
48 |
+
st.text_area("Medical Report Diagnosis", diagnosis, height=300)
|
49 |
+
|
50 |
+
if __name__ == "__main__":
|
51 |
+
main()
|