Spaces:
Running
Running
import streamlit as st | |
import requests | |
import pdfplumber | |
# Configurar a URL e a chave de API do seu modelo personalizado | |
api_url = 'https://chatgpt.com/g/g-AFG1NiIdw-labs-resume/api' | |
api_key = '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' | |
st.title('Labs Resume') | |
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!') | |
# Função para extrair texto de um arquivo PDF | |
def extract_text_from_pdf(file): | |
with pdfplumber.open(file) as pdf: | |
text = "" | |
for page in pdf.pages: | |
text += page.extract_text() + "\n" | |
return text | |
# Função para enviar texto ao GPT-4 e obter a resposta | |
def query_gpt4(prompt): | |
headers = { | |
'Authorization': f'Bearer {api_key}', | |
'Content-Type': 'application/json' | |
} | |
data = { | |
'prompt': prompt, | |
'max_tokens': 150 | |
} | |
response = requests.post(api_url, headers=headers, json=data) | |
if response.status_code == 200: | |
return response.json()['choices'][0]['text'].strip() | |
else: | |
return f"Erro: {response.status_code} - {response.text}" | |
# Interface de chat e upload de arquivo | |
st.write("### Interação com o GPT-4") | |
chat_input = st.text_input("Digite sua pergunta aqui:") | |
submit_chat = st.button("Enviar") | |
uploaded_file = st.file_uploader("Faça upload do arquivo PDF ou .txt", type=["pdf", "txt"]) | |
submit_file = st.button("Enviar Arquivo") | |
# Processar entrada de chat | |
if submit_chat and chat_input: | |
response = query_gpt4(chat_input) | |
st.write("Resposta do GPT-4:") | |
st.write(response) | |
# Processar upload de arquivo | |
if submit_file and uploaded_file is not None: | |
if uploaded_file.type == "application/pdf": | |
text = extract_text_from_pdf(uploaded_file) | |
elif uploaded_file.type == "text/plain": | |
text = str(uploaded_file.read(), "utf-8") | |
response = query_gpt4(text) | |
st.write("Resumo do Exame:") | |
st.write(response) | |
<iframe> | |
src="https://chatgpt.com/g/g-AFG1NiIdw-labs-resume" | |
style="height: 450px; width: 100%;" | |
</iframe> | |