Download app.py from Alfasign/newpd: direct link, hf CLI and curl.
- Browser
- Download file 2.09 kB
-
https://huggingface.co/spaces/Alfasign/newpd/resolve/main/app.py
- Command line
-
hf download hf://spaces/Alfasign/newpd/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Alfasign/newpd/resolve/main/app.py
2.09 kB
| import streamlit as st | |
| from transformers import pipeline | |
| # CSS für die Anpassung der Ansicht | |
| st.markdown(""" | |
| <style> | |
| .stSidebar { | |
| background-color: #f2f2f2; | |
| } | |
| .stText { | |
| color: #333333; | |
| } | |
| .stButton>button { | |
| background-color: #4CAF50; | |
| color: white; | |
| } | |
| .stTitle { | |
| color: #ffbf00; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # Sidebar-Inhalte | |
| st.sidebar.title('⭐️EinfachChat⭐️') | |
| # About section | |
| st.sidebar.markdown(''' | |
| ## Über die App | |
| Diese ist eine LLM-powered chatbot app und wurde erstellt mit : | |
| - [Streamlit](https://streamlit.io/) | |
| - [LangChain](https://python.langchain.com/) | |
| - [Huggingface](https://huggingface.com/) | |
| ''') | |
| # Image | |
| st.sidebar.markdown('<img src="https://einfachalex.net/wp-content/uploads/2023/05/4-5.png" alt="Beschreibung des Bildes" width="200" style="float:left;">', unsafe_allow_html=True) | |
| # Made with love | |
| st.sidebar.write('Made with ❤️💬 by [EinfachAlex](https://github.com/alfcodex)') | |
| # Hugging Face Textklassifikations-Pipeline | |
| classifier = pipeline('text-classification', model='bert-base-uncased', tokenizer='bert-base-uncased') | |
| # Funktion zum Extrahieren des Texts aus einem PDF (bereits vorhanden) | |
| # Funktion zur Textklassifikation | |
| def classify_text(text): | |
| result = classifier(text) | |
| return result | |
| # Benutzerdatei hochladen und verarbeiten (bereits vorhanden) | |
| # Verarbeite das hochgeladene Dokument | |
| if st.button("Verarbeiten"): | |
| if file is not None: | |
| if file.type.split('/')[1] == 'pdf': | |
| pdf_text = extract_text_from_pdf(file) | |
| st.write("Text aus PDF extrahiert:") | |
| st.write(pdf_text) | |
| elif file.type.split('/')[1] == 'plain': | |
| text_content = file.read().decode('utf-8') | |
| st.write("Textdokumentinhalt:") | |
| st.write(text_content) | |
| # Klassifiziere den Text | |
| classification_result = classify_text(text_content) | |
| st.write("Klassifikationsergebnis:") | |
| st.write(classification_result) | |
| else: | |
| st.warning("Keine Datei ausgewählt.") | |