Commit ·
b7e4c27
1
Parent(s): 4c37462
2ND
Browse files
.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
AIzaSyBbzFCa84gRACICF9JrjGtonTl8UIdNOPs
|
app.py
CHANGED
|
@@ -4,25 +4,22 @@ from PyPDF2 import PdfReader
|
|
| 4 |
from PIL import Image
|
| 5 |
import re
|
| 6 |
from collections import Counter
|
| 7 |
-
|
| 8 |
from streamlit_option_menu import option_menu
|
| 9 |
|
| 10 |
-
# Get the API
|
| 11 |
api_key = os.getenv("GEMINI_API_KEY")
|
| 12 |
|
| 13 |
if api_key is None:
|
| 14 |
-
st.error("API key not found. Please set the
|
| 15 |
else:
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
genai.configure(api_key=api_key)
|
| 19 |
-
model = genai.GenerativeModel(MODEL_ID)
|
| 20 |
-
chat = model.start_chat()
|
| 21 |
|
| 22 |
st.set_page_config(
|
| 23 |
page_title="AI-Powered Historical Document Analysis",
|
| 24 |
layout="wide",
|
| 25 |
-
page_icon="
|
| 26 |
)
|
| 27 |
|
| 28 |
# Center content and enhance visual style
|
|
@@ -42,6 +39,12 @@ else:
|
|
| 42 |
h1, h2, h3, h4, h5 {
|
| 43 |
color: #2c3e50;
|
| 44 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
</style>
|
| 46 |
""", unsafe_allow_html=True)
|
| 47 |
|
|
@@ -54,17 +57,18 @@ else:
|
|
| 54 |
to extract key information, provide contextual insights, and visualize data on modern maps.
|
| 55 |
""")
|
| 56 |
|
| 57 |
-
#
|
|
|
|
| 58 |
selected_tab = option_menu(
|
| 59 |
-
menu_title="
|
| 60 |
options=["Home", "Key Points", "General Contents", "Historical Context"],
|
| 61 |
icons=["house", "key", "book", "clock"],
|
| 62 |
menu_icon="cast",
|
| 63 |
default_index=0,
|
| 64 |
orientation="horizontal",
|
| 65 |
styles={
|
| 66 |
-
"container": {"display": "flex", "justify-content": "center", "align-items": "center"},
|
| 67 |
-
"nav-link": {"font-size": "
|
| 68 |
"nav-link-selected": {"background-color": "#007bff", "color": "white", "border-radius": "5px"}
|
| 69 |
}
|
| 70 |
)
|
|
@@ -91,9 +95,8 @@ else:
|
|
| 91 |
def contextualize_document(text):
|
| 92 |
"""Generate historical context based on document text."""
|
| 93 |
try:
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
return response.text
|
| 97 |
except Exception as e:
|
| 98 |
return f"Error: {e}"
|
| 99 |
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
import re
|
| 6 |
from collections import Counter
|
| 7 |
+
from huggingface_hub import InferenceClient
|
| 8 |
from streamlit_option_menu import option_menu
|
| 9 |
|
| 10 |
+
# Get the Hugging Face API token from environment variable
|
| 11 |
api_key = os.getenv("GEMINI_API_KEY")
|
| 12 |
|
| 13 |
if api_key is None:
|
| 14 |
+
st.error("API key not found. Please set the HF_API_KEY environment variable.")
|
| 15 |
else:
|
| 16 |
+
# Initialize Hugging Face Inference Client
|
| 17 |
+
client = InferenceClient(api_key=api_key)
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
st.set_page_config(
|
| 20 |
page_title="AI-Powered Historical Document Analysis",
|
| 21 |
layout="wide",
|
| 22 |
+
page_icon=":scroll:" # Updated to avoid UnicodeEncodeError
|
| 23 |
)
|
| 24 |
|
| 25 |
# Center content and enhance visual style
|
|
|
|
| 39 |
h1, h2, h3, h4, h5 {
|
| 40 |
color: #2c3e50;
|
| 41 |
}
|
| 42 |
+
.nav-label {
|
| 43 |
+
font-size: 16px;
|
| 44 |
+
font-weight: bold;
|
| 45 |
+
margin-bottom: 5px;
|
| 46 |
+
text-align: center;
|
| 47 |
+
}
|
| 48 |
</style>
|
| 49 |
""", unsafe_allow_html=True)
|
| 50 |
|
|
|
|
| 57 |
to extract key information, provide contextual insights, and visualize data on modern maps.
|
| 58 |
""")
|
| 59 |
|
| 60 |
+
# Compact Navigation
|
| 61 |
+
st.markdown("<div class='nav-label'>Navigation</div>", unsafe_allow_html=True)
|
| 62 |
selected_tab = option_menu(
|
| 63 |
+
menu_title="",
|
| 64 |
options=["Home", "Key Points", "General Contents", "Historical Context"],
|
| 65 |
icons=["house", "key", "book", "clock"],
|
| 66 |
menu_icon="cast",
|
| 67 |
default_index=0,
|
| 68 |
orientation="horizontal",
|
| 69 |
styles={
|
| 70 |
+
"container": {"display": "flex", "justify-content": "center", "align-items": "center", "gap": "10px"},
|
| 71 |
+
"nav-link": {"font-size": "14px", "text-align": "center", "padding": "5px 10px", "--hover-color": "#f0f0f0"},
|
| 72 |
"nav-link-selected": {"background-color": "#007bff", "color": "white", "border-radius": "5px"}
|
| 73 |
}
|
| 74 |
)
|
|
|
|
| 95 |
def contextualize_document(text):
|
| 96 |
"""Generate historical context based on document text."""
|
| 97 |
try:
|
| 98 |
+
response = client.text_generation(model="gpt-neo-2.7B", inputs=f"Provide historical context for the following text:\n\n{text[:1000]}")
|
| 99 |
+
return response["generated_text"]
|
|
|
|
| 100 |
except Exception as e:
|
| 101 |
return f"Error: {e}"
|
| 102 |
|