Spaces:
Running
Running
Update pages/Exames.py
Browse files- pages/Exames.py +23 -12
pages/Exames.py
CHANGED
@@ -3,12 +3,13 @@ import requests
|
|
3 |
import pdfplumber
|
4 |
|
5 |
# Configurar a URL e a chave de API do seu modelo personalizado
|
6 |
-
api_url = 'https://
|
7 |
-
api_key = '
|
8 |
|
9 |
st.title('Labs Resume')
|
10 |
st.subheader('Leitor de exames, abrevia resultados e respeita a Lei de proteção de dados. Orientações de saúde, procure seu médico!')
|
11 |
|
|
|
12 |
def extract_text_from_pdf(file):
|
13 |
with pdfplumber.open(file) as pdf:
|
14 |
text = ""
|
@@ -16,13 +17,14 @@ def extract_text_from_pdf(file):
|
|
16 |
text += page.extract_text() + "\n"
|
17 |
return text
|
18 |
|
19 |
-
|
|
|
20 |
headers = {
|
21 |
'Authorization': f'Bearer {api_key}',
|
22 |
'Content-Type': 'application/json'
|
23 |
}
|
24 |
data = {
|
25 |
-
'prompt':
|
26 |
'max_tokens': 150
|
27 |
}
|
28 |
response = requests.post(api_url, headers=headers, json=data)
|
@@ -31,19 +33,28 @@ def summarize_exam(text):
|
|
31 |
else:
|
32 |
return f"Erro: {response.status_code} - {response.text}"
|
33 |
|
34 |
-
# Interface
|
|
|
|
|
|
|
|
|
|
|
35 |
uploaded_file = st.file_uploader("Faça upload do arquivo PDF ou .txt", type=["pdf", "txt"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
|
|
|
38 |
if uploaded_file.type == "application/pdf":
|
39 |
text = extract_text_from_pdf(uploaded_file)
|
40 |
elif uploaded_file.type == "text/plain":
|
41 |
text = str(uploaded_file.read(), "utf-8")
|
42 |
|
43 |
-
|
44 |
st.write("Resumo do Exame:")
|
45 |
-
st.write(
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
# st.markdown("## Em breve!")
|
|
|
3 |
import pdfplumber
|
4 |
|
5 |
# Configurar a URL e a chave de API do seu modelo personalizado
|
6 |
+
api_url = 'https://sua-url-na-loja-gpt.com/api'
|
7 |
+
api_key = 'sua_chave_api_aqui'
|
8 |
|
9 |
st.title('Labs Resume')
|
10 |
st.subheader('Leitor de exames, abrevia resultados e respeita a Lei de proteção de dados. Orientações de saúde, procure seu médico!')
|
11 |
|
12 |
+
# Função para extrair texto de um arquivo PDF
|
13 |
def extract_text_from_pdf(file):
|
14 |
with pdfplumber.open(file) as pdf:
|
15 |
text = ""
|
|
|
17 |
text += page.extract_text() + "\n"
|
18 |
return text
|
19 |
|
20 |
+
# Função para enviar texto ao GPT-4 e obter a resposta
|
21 |
+
def query_gpt4(prompt):
|
22 |
headers = {
|
23 |
'Authorization': f'Bearer {api_key}',
|
24 |
'Content-Type': 'application/json'
|
25 |
}
|
26 |
data = {
|
27 |
+
'prompt': prompt,
|
28 |
'max_tokens': 150
|
29 |
}
|
30 |
response = requests.post(api_url, headers=headers, json=data)
|
|
|
33 |
else:
|
34 |
return f"Erro: {response.status_code} - {response.text}"
|
35 |
|
36 |
+
# Interface de chat e upload de arquivo
|
37 |
+
st.write("### Interação com o GPT-4")
|
38 |
+
|
39 |
+
chat_input = st.text_input("Digite sua pergunta aqui:")
|
40 |
+
submit_chat = st.button("Enviar")
|
41 |
+
|
42 |
uploaded_file = st.file_uploader("Faça upload do arquivo PDF ou .txt", type=["pdf", "txt"])
|
43 |
+
submit_file = st.button("Enviar Arquivo")
|
44 |
+
|
45 |
+
# Processar entrada de chat
|
46 |
+
if submit_chat and chat_input:
|
47 |
+
response = query_gpt4(chat_input)
|
48 |
+
st.write("Resposta do GPT-4:")
|
49 |
+
st.write(response)
|
50 |
|
51 |
+
# Processar upload de arquivo
|
52 |
+
if submit_file and uploaded_file is not None:
|
53 |
if uploaded_file.type == "application/pdf":
|
54 |
text = extract_text_from_pdf(uploaded_file)
|
55 |
elif uploaded_file.type == "text/plain":
|
56 |
text = str(uploaded_file.read(), "utf-8")
|
57 |
|
58 |
+
response = query_gpt4(text)
|
59 |
st.write("Resumo do Exame:")
|
60 |
+
st.write(response)
|
|
|
|
|
|
|
|