amasood commited on
Commit
133f73d
·
verified ·
1 Parent(s): a0245e7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -0
app.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from groq import Groq
4
+ import PyPDF2
5
+ import pdfplumber
6
+
7
+ # Initialize Groq client
8
+ client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
9
+
10
+ # Function to process PDF report
11
+ def process_pdf(file):
12
+ text = ""
13
+ with pdfplumber.open(file) as pdf:
14
+ for page in pdf.pages:
15
+ text += page.extract_text()
16
+ return text
17
+
18
+ # Function to query Groq API
19
+ def query_groq(prompt):
20
+ chat_completion = client.chat.completions.create(
21
+ messages=[{"role": "user", "content": prompt}],
22
+ model="llama-3.3-70b-versatile",
23
+ )
24
+ return chat_completion.choices[0].message.content
25
+
26
+ # Streamlit interface
27
+ st.set_page_config(page_title="vDoc", layout="wide")
28
+
29
+ st.title("🌟 vDoc: Your Virtual Doctor 🌟")
30
+ st.sidebar.header("User Input Options")
31
+
32
+ # Input Section
33
+ symptoms = st.sidebar.text_area("Describe your symptoms")
34
+ uploaded_files = st.sidebar.file_uploader(
35
+ "Upload Medical Test Reports (PDF)", type=["pdf"], accept_multiple_files=True
36
+ )
37
+ medical_history = st.sidebar.text_area("Medical history or medications")
38
+
39
+ if st.sidebar.button("Submit"):
40
+ st.subheader("Diagnosis")
41
+
42
+ # Collect and process inputs
43
+ input_data = []
44
+ if symptoms:
45
+ input_data.append(f"Symptoms: {symptoms}")
46
+ if uploaded_files:
47
+ for file in uploaded_files:
48
+ report_text = process_pdf(file)
49
+ input_data.append(f"Test Report: {report_text}")
50
+ if medical_history:
51
+ input_data.append(f"Medical History: {medical_history}")
52
+
53
+ # Send inputs to Groq API for analysis
54
+ combined_input = "\n".join(input_data)
55
+ if combined_input:
56
+ response = query_groq(f"Diagnose the following medical issue:\n{combined_input}")
57
+ st.write(response)
58
+ else:
59
+ st.warning("Please provide at least one input for diagnosis.")
60
+
61
+ # Chatbot Section
62
+ st.subheader("🤖 Chat with vDoc")
63
+ chat_input = st.text_input("Your question or response", "")
64
+ if st.button("Ask"):
65
+ if chat_input:
66
+ chat_response = query_groq(chat_input)
67
+ st.write(chat_response)
68
+ else:
69
+ st.warning("Please enter a question or response.")
70
+
71
+ # Additional Features
72
+ st.sidebar.subheader("Additional Features")
73
+ if st.sidebar.button("Explain Test Reports"):
74
+ if uploaded_files:
75
+ for file in uploaded_files:
76
+ report_text = process_pdf(file)
77
+ explanation = query_groq(f"Explain the following test report:\n{report_text}")
78
+ st.subheader(f"Explanation for {file.name}")
79
+ st.write(explanation)
80
+ else:
81
+ st.sidebar.warning("Upload test reports to get explanations.")
82
+
83
+ medicine_name = st.sidebar.text_input("Enter Medicine Name for Details")
84
+ if st.sidebar.button("Get Medicine Info"):
85
+ if medicine_name:
86
+ medicine_info = query_groq(f"Explain the use and details of the medicine: {medicine_name}")
87
+ st.subheader(f"Details about {medicine_name}")
88
+ st.write(medicine_info)
89
+ else:
90
+ st.sidebar.warning("Enter a medicine name to get details.")