Spaces:
Sleeping
Sleeping
import streamlit as st | |
from transformers import pipeline | |
from PIL import Image | |
logo_path = "college_logo.png" | |
if os.path.exists(logo_path): | |
logo = Image.open(logo_path) | |
else: | |
print(f"File {logo_path} not found. Please ensure it is in the correct directory.") | |
# Step 1: Define College Data | |
college_about = """ | |
The college was notified to work from 16th July 2003 on the directions of the then care-taker Minister for education Mr. Khan Muhammad Dahri. | |
At the beginning, the college had no staff of its own, so it was borrowed from Government Degree College Sakrand. | |
The college started its classes in the afternoon at Government High School Daulatpur as it had no specific building. | |
With the help of the EDO Education, the possession of the Government Girls High School (Old) Daulatpur was given to the college now college have 2 four bliding and much more fecilaty. | |
""" | |
faculty_data = """ | |
1. Prof Mahfooz Khan (Associate Prof, Islamiat) | |
2. Muhammad Aslam Palli (Associate Prof, Physics) | |
3. Abdul Rahman Gaincho (Botany) | |
4. M. Essa Samego (Lecturer, Islamiat) | |
5. Ali Aijaz Dahri (Lecturer, Chemistry) | |
6. Asif Ali Rajput (Lecturer, Physics) | |
7. Fida Hussain (Lecturer, Math) | |
8. Zulfiqar Ali (Senior Librarian) | |
""" | |
facilities = """ | |
Facilities available: | |
1. Digital library with 20+ computers | |
2. Parks: Alquran Park and Botany Park with 50+ plants | |
3. Labs: Zoology, Botany, Physics, Chemistry | |
4. Parking area | |
5. Solar system and RO Plant | |
""" | |
# Step 2: Initialize QA Model | |
from transformers import pipeline | |
# Ensure you specify the framework explicitly | |
qa_model = pipeline( | |
"question-answering", | |
model="deepset/roberta-base-squad2", | |
framework="pt" # Use "pt" for PyTorch or "tf" for TensorFlow | |
) | |
# Step 3: Define Application Functions | |
def answer_query(question): | |
context = f"{college_about}\n\n{faculty_data}\n\n{facilities}" | |
response = qa_model(question=question, context=context) | |
return response["answer"] | |
# Step 4: Streamlit UI | |
st.set_page_config(page_title="College RAG App", layout="wide", initial_sidebar_state="expanded") | |
# Display Logo | |
logo = Image.open("college_logo.png") | |
st.image(logo, width=200) | |
# App Title and Description | |
st.title("Government Boys Degree College Daulatpur") | |
st.subheader("Welcome to our College Information RAG App") | |
# Sidebar Navigation | |
menu = ["About College", "Faculty and Staff", "Facilities", "Ask a Question", "Contact Us"] | |
choice = st.sidebar.selectbox("Navigation", menu) | |
# Content Based on Navigation | |
if choice == "About College": | |
st.markdown(f"<div style='background-color: #A5D6A7; padding: 10px; border-radius: 10px; color: #424242;'>{college_about}</div>", unsafe_allow_html=True) | |
elif choice == "Faculty and Staff": | |
st.markdown("### Faculty Details") | |
st.text(faculty_data) | |
elif choice == "Facilities": | |
st.markdown("### Facilities") | |
st.text(facilities) | |
elif choice == "Ask a Question": | |
st.markdown("### Ask a Question About the College") | |
question = st.text_input("Type your question:") | |
if question: | |
answer = answer_query(question) | |
st.success(f"Answer: {answer}") | |
elif choice == "Contact Us": | |
st.markdown("### Contact Details") | |
st.markdown(""" | |
- **Location:** National Highway N6 bypass Daulatpur | |
- **Phone:** +92 300 3003249 | |
- **Email:** othoirshad@gmail.com | |
- [Visit our Facebook Page](https://www.facebook.com/share/19j9Z1iEvz/) | |
""") | |
st.markdown("### Made by Musawir Manzoor") | |