drguilhermeapolinario commited on
Commit
9361497
·
verified ·
1 Parent(s): 09fb6a9

Update views/exame.py

Browse files
Files changed (1) hide show
  1. views/exame.py +6 -83
views/exame.py CHANGED
@@ -1,83 +1,6 @@
1
- import streamlit as st
2
- from openai import OpenAI
3
- from langchain.document_loaders import UnstructuredFileLoader
4
-
5
- st.title("Extração de resultados")
6
-
7
-
8
- def load_document(file_path, mode="single"):
9
- loader = UnstructuredFileLoader(file_path, mode=mode)
10
- docs = loader.load()
11
-
12
- if mode == "single":
13
- return docs[0].page_content, []
14
- elif mode == "elements":
15
- return " ".join([str(doc.page_content) for doc in docs]), docs
16
-
17
-
18
- # Sidebar para entrada de chave API e seleção de modelo
19
- with st.sidebar:
20
- openai_api_key = st.text_input(
21
- "OpenAI API Key", key="chatbot_api_key", type="password"
22
- )
23
- st.markdown(
24
- "[Pegue aqui sua chave OpenAI API](https://platform.openai.com/account/api-keys)"
25
- )
26
-
27
- uploaded_file = st.file_uploader(
28
- "Escolha um arquivo PDF ou imagem", type=["pdf", "png", "jpg", "jpeg", "docx"]
29
- )
30
-
31
- if st.button("Limpar Conversa"):
32
- st.session_state["messages"] = [
33
- {"role": "assistant", "content": "How can I help you?"}
34
- ]
35
- st.experimental_rerun()
36
-
37
- st.title("💬 Chatbot")
38
- st.caption("🚀 A Streamlit chatbot powered by OpenAI")
39
-
40
- models = "asst_wXmB8syPqCxPWGtNqiuOXQtn"
41
-
42
- if "messages" not in st.session_state:
43
- st.session_state["messages"] = [
44
- {"role": "assistant", "content": "How can I help you?"}
45
- ]
46
-
47
- for msg in st.session_state.messages:
48
- st.chat_message(msg["role"]).write(msg["content"])
49
-
50
-
51
- if prompt := st.chat_input():
52
- if not openai_api_key:
53
- st.info("Insira sua chave API OpenAI para continuar.")
54
- st.stop()
55
-
56
- client = OpenAI(api_key=openai_api_key)
57
- st.session_state.messages.append({"role": "user", "content": prompt})
58
- st.chat_message("user").write(prompt)
59
- response = client.chat.completions.create(
60
- model=models, messages=st.session_state.messages
61
- )
62
- msg = response.choices[0].message.content
63
- st.session_state.messages.append({"role": "assistant", "content": msg})
64
- st.chat_message("assistant").write(msg)
65
-
66
-
67
- if uploaded_file is not None:
68
- data = load_document(st.file_uploader)
69
- if data := st.session_state.get("uploaded_file", None) is not None and st.button(
70
- "Enviar", type="primary"
71
- ):
72
- if data is not None:
73
- st.session_state.exames({"role": "uploaded_file", "content": data})
74
- resposta = client.chat.completions.create(
75
- model=models, messages=st.session_state.exames
76
- )
77
- msg = resposta.choices[0].message.content
78
- st.session_state.exames.append({"role": "assistant", "content": msg})
79
- st.chat_message("assistant").write(msg)
80
- else:
81
- st.error("Não foi possível extrair texto do arquivo carregado.")
82
- else:
83
- st.warning("Por favor, carregue um arquivo antes de enviar.")
 
1
+ import streamlit as st
2
+
3
+
4
+ st.title("Extração de resultados")
5
+
6
+ st.write('## Em breve!')