Spaces:
Sleeping
Sleeping
Commit
·
2e64cea
1
Parent(s):
21bcf26
build chain II, password, explained limitations
Browse files
app.py
CHANGED
|
@@ -11,7 +11,10 @@ def gpt4_new(prompt_text):
|
|
| 11 |
response = client.chat.completions.create(
|
| 12 |
model="gpt-4",
|
| 13 |
messages=[{"role": "system",
|
| 14 |
-
"content": "Du bist eine Maschine, die Dokumente klassifiziert."
|
|
|
|
|
|
|
|
|
|
| 15 |
{"role": "user", "content": prompt_text}])
|
| 16 |
return response.choices[0].message.content
|
| 17 |
|
|
@@ -74,33 +77,42 @@ def json_open(filename):
|
|
| 74 |
|
| 75 |
|
| 76 |
def main():
|
|
|
|
| 77 |
st.title("Doc Classifier")
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
|
| 106 |
if __name__ == "__main__":
|
|
@@ -109,8 +121,15 @@ if __name__ == "__main__":
|
|
| 109 |
auftrag_1a = "Klassifiziere dieses Dokument nach "
|
| 110 |
auftrag_1b = "diesen 'Baubranchen Disziplinen': "
|
| 111 |
auftrag_1c = "diesen 'Dokumententypen': "
|
| 112 |
-
Baubranchen_Disziplinen = ['
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
Dokumententypen = ['Fotodokumentation', 'Projektdokumentation (PD)', 'Objektdokumentation (OD)',
|
| 115 |
'Prozessdokumentation', 'Fachdokumentation', 'Anlagedokumentation']
|
| 116 |
#print(str(Baubranchen_Disziplinen))
|
|
|
|
| 11 |
response = client.chat.completions.create(
|
| 12 |
model="gpt-4",
|
| 13 |
messages=[{"role": "system",
|
| 14 |
+
"content": "Du bist eine Maschine, die Dokumente klassifiziert."
|
| 15 |
+
"Du gibts möglichst kurze Antworten, am besten maschnienlesbar"
|
| 16 |
+
"und nur ein einziges Wort. Du gibts keine Erklärungen oder"
|
| 17 |
+
"Begründungen."},
|
| 18 |
{"role": "user", "content": prompt_text}])
|
| 19 |
return response.choices[0].message.content
|
| 20 |
|
|
|
|
| 77 |
|
| 78 |
|
| 79 |
def main():
|
| 80 |
+
ASK_ASH_PASSWORD = os.environ["ASK_ASH_PASSWORD"]
|
| 81 |
st.title("Doc Classifier")
|
| 82 |
+
st.subheader("Limitationen: ")
|
| 83 |
+
st.write("bisher nur PDFs")
|
| 84 |
+
st.write("nur Disziplin und Doc typ.")
|
| 85 |
+
st.write("Dokumenten Grösse ist stark limitiert")
|
| 86 |
+
st.write("macht noch viele Fehler, vor allem bei Koordination, Datennetz usw, (unklare Disziplinen)")
|
| 87 |
+
st.write("")
|
| 88 |
+
|
| 89 |
+
if st.text_input("ASK_ASH_PASSWORD: ", type="password") == ASK_ASH_PASSWORD:
|
| 90 |
+
uploaded_file = st.file_uploader("PDF Dokument", accept_multiple_files=False)
|
| 91 |
+
#print(uploaded_file)
|
| 92 |
+
#print(uploaded_file.name)
|
| 93 |
+
if st.button("classify KBOB!"):
|
| 94 |
+
if uploaded_file is not None:
|
| 95 |
+
with st.spinner("GPT4 at work"):
|
| 96 |
+
pdf_text = str(get_pdf_text(uploaded_file))
|
| 97 |
+
prompt_1 = auftrag_1a + auftrag_1b + str(Baubranchen_Disziplinen) + pdf_text
|
| 98 |
+
answer_1 = gpt4_new(prompt_1)
|
| 99 |
+
print(prompt_1)
|
| 100 |
+
st.write(answer_1)
|
| 101 |
+
with st.spinner("GPT4 at work"):
|
| 102 |
+
prompt_2 = auftrag_1a + auftrag_1c + str(Dokumententypen) + pdf_text
|
| 103 |
+
answer_2 = gpt4_new(prompt_2)
|
| 104 |
+
print(prompt_2)
|
| 105 |
+
st.write(answer_2)
|
| 106 |
+
|
| 107 |
+
#with st.spinner("GPT4 at work"):
|
| 108 |
+
#prompt_3 =
|
| 109 |
+
#answer_3 =
|
| 110 |
+
#print(prompt_2)
|
| 111 |
+
st.success("work done, saved")
|
| 112 |
+
|
| 113 |
+
#st.download_button("download txt", json_open("gpt4_responses.txt"), file_name="gpt4_responses.txt")
|
| 114 |
+
else:
|
| 115 |
+
st.warning("no file")
|
| 116 |
|
| 117 |
|
| 118 |
if __name__ == "__main__":
|
|
|
|
| 121 |
auftrag_1a = "Klassifiziere dieses Dokument nach "
|
| 122 |
auftrag_1b = "diesen 'Baubranchen Disziplinen': "
|
| 123 |
auftrag_1c = "diesen 'Dokumententypen': "
|
| 124 |
+
Baubranchen_Disziplinen = ['A-Architektur', 'B-Bauphysik', 'C-Rohrpostanlagen', 'D-Datennetz', 'E-Elektroanlagen',
|
| 125 |
+
'F-Fassadenplanung', 'G-Küche', 'H-Heizung', 'I-Innenausbau', 'K-Kälte', 'L-Lüftung',
|
| 126 |
+
'M-Medizintechnik', 'N-Fördertechnik', 'O-Gebäudebetrieb', 'P-Sprinkler',
|
| 127 |
+
'Q-Brandschutz', 'R-Koordination', 'S-Sanitär', 'T-Tragwerksplanung', 'W-Informatik',
|
| 128 |
+
'Z-Lichtplanung']
|
| 129 |
+
auftrag_2 = "gib nur den am besten passendsten Eintrag zurück. " \
|
| 130 |
+
"Keine weiteren Ausführungen oder Erklärungen. " \
|
| 131 |
+
"Antworte am besten in einem Wort. " \
|
| 132 |
+
"Hier der Dokumenteninhalt: "
|
| 133 |
Dokumententypen = ['Fotodokumentation', 'Projektdokumentation (PD)', 'Objektdokumentation (OD)',
|
| 134 |
'Prozessdokumentation', 'Fachdokumentation', 'Anlagedokumentation']
|
| 135 |
#print(str(Baubranchen_Disziplinen))
|