Upload 4 files
Browse files
.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
OPENAI_API_KEY=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
|
README.md
CHANGED
|
@@ -1,12 +1,65 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# UET Chatbot
|
| 2 |
+
|
| 3 |
+
A Streamlit-based chatbot for the University of Engineering and Technology (UET) Peshawar and UET Mardan. This chatbot provides information about academic programs, admission requirements, campus facilities, and other university-related queries.
|
| 4 |
+
|
| 5 |
+
## Features
|
| 6 |
+
|
| 7 |
+
- Interactive chat interface using Streamlit
|
| 8 |
+
- Powered by OpenAI's GPT-3.5 Turbo
|
| 9 |
+
- Provides information about both UET Peshawar and UET Mardan
|
| 10 |
+
- Maintains conversation history during the session
|
| 11 |
+
- Professional and helpful responses
|
| 12 |
+
|
| 13 |
+
## Setup
|
| 14 |
+
|
| 15 |
+
1. Clone this repository:
|
| 16 |
+
```bash
|
| 17 |
+
git clone https://github.com/yourusername/university-chatbot.git
|
| 18 |
+
cd university-chatbot
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
2. Install the required dependencies:
|
| 22 |
+
```bash
|
| 23 |
+
pip install -r requirements.txt
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
3. Create a `.env` file in the root directory and add your OpenAI API key:
|
| 27 |
+
```
|
| 28 |
+
OPENAI_API_KEY=your_api_key_here
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
## Running the Chatbot
|
| 32 |
+
|
| 33 |
+
To run the chatbot locally:
|
| 34 |
+
```bash
|
| 35 |
+
streamlit run app.py
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
## Deployment on Hugging Face
|
| 39 |
+
|
| 40 |
+
1. Create a new Space on Hugging Face
|
| 41 |
+
2. Choose Streamlit as the SDK
|
| 42 |
+
3. Upload the repository files
|
| 43 |
+
4. Add your OpenAI API key in the Space's Secrets section
|
| 44 |
+
5. Deploy the Space
|
| 45 |
+
|
| 46 |
+
## Usage
|
| 47 |
+
|
| 48 |
+
1. Open the chatbot interface
|
| 49 |
+
2. Type your question in the chat input
|
| 50 |
+
3. The chatbot will respond with relevant information about UET
|
| 51 |
+
4. You can ask questions about:
|
| 52 |
+
- Academic programs
|
| 53 |
+
- Admission requirements
|
| 54 |
+
- Campus facilities
|
| 55 |
+
- University policies
|
| 56 |
+
- Important dates
|
| 57 |
+
- And more!
|
| 58 |
+
|
| 59 |
+
## Contributing
|
| 60 |
+
|
| 61 |
+
Feel free to submit issues and enhancement requests!
|
| 62 |
+
|
| 63 |
+
## License
|
| 64 |
+
|
| 65 |
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
app.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import openai
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# Load environment variables
|
| 7 |
+
load_dotenv()
|
| 8 |
+
|
| 9 |
+
# Configure OpenAI API
|
| 10 |
+
client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 11 |
+
|
| 12 |
+
# System prompt template
|
| 13 |
+
SYSTEM_PROMPT = """You are an AI assistant for the University of Engineering and Technology (UET).
|
| 14 |
+
Your role is to provide accurate and helpful information about {university}.
|
| 15 |
+
You should:
|
| 16 |
+
1. Provide information about academic programs, admission requirements, and campus facilities
|
| 17 |
+
2. Answer questions about university policies, procedures, and important dates
|
| 18 |
+
3. Guide students about registration, courses, and academic matters
|
| 19 |
+
4. Share information about research opportunities and faculty
|
| 20 |
+
5. Direct users to official university resources when needed
|
| 21 |
+
|
| 22 |
+
Always maintain a professional and helpful tone. If you're unsure about any information,
|
| 23 |
+
acknowledge the limitation and suggest contacting the university directly."""
|
| 24 |
+
|
| 25 |
+
def get_chatbot_response(messages):
|
| 26 |
+
"""Get response from OpenAI API"""
|
| 27 |
+
try:
|
| 28 |
+
response = client.chat.completions.create(
|
| 29 |
+
model="gpt-3.5-turbo",
|
| 30 |
+
messages=messages,
|
| 31 |
+
temperature=0.7,
|
| 32 |
+
max_tokens=500
|
| 33 |
+
)
|
| 34 |
+
return response.choices[0].message.content
|
| 35 |
+
except Exception as e:
|
| 36 |
+
return f"Error: {str(e)}"
|
| 37 |
+
|
| 38 |
+
def main():
|
| 39 |
+
st.title("UET Chatbot")
|
| 40 |
+
st.write("Welcome to the UET Chatbot! Ask me anything about UET Peshawar or UET Mardan.")
|
| 41 |
+
|
| 42 |
+
# Dropdown to select university
|
| 43 |
+
university = st.selectbox("Select University", ["UET Peshawar", "UET Mardan"])
|
| 44 |
+
|
| 45 |
+
# Initialize chat history
|
| 46 |
+
if "messages" not in st.session_state:
|
| 47 |
+
st.session_state.messages = [{"role": "system", "content": SYSTEM_PROMPT.format(university=university)}]
|
| 48 |
+
|
| 49 |
+
# Update system prompt if university changes
|
| 50 |
+
if st.session_state.messages[0]["content"] != SYSTEM_PROMPT.format(university=university):
|
| 51 |
+
st.session_state.messages = [{"role": "system", "content": SYSTEM_PROMPT.format(university=university)}]
|
| 52 |
+
|
| 53 |
+
# Display chat history
|
| 54 |
+
for message in st.session_state.messages:
|
| 55 |
+
if message["role"] != "system":
|
| 56 |
+
with st.chat_message(message["role"]):
|
| 57 |
+
st.write(message["content"])
|
| 58 |
+
|
| 59 |
+
# Chat input
|
| 60 |
+
if prompt := st.chat_input("What would you like to know?"):
|
| 61 |
+
# Add user message to chat history
|
| 62 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 63 |
+
|
| 64 |
+
# Display user message
|
| 65 |
+
with st.chat_message("user"):
|
| 66 |
+
st.write(prompt)
|
| 67 |
+
|
| 68 |
+
# Get chatbot response
|
| 69 |
+
with st.chat_message("assistant"):
|
| 70 |
+
response = get_chatbot_response(st.session_state.messages)
|
| 71 |
+
st.write(response)
|
| 72 |
+
|
| 73 |
+
# Add assistant response to chat history
|
| 74 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
| 75 |
+
|
| 76 |
+
if __name__ == "__main__":
|
| 77 |
+
main()
|
requirements.txt
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Core dependencies
|
| 2 |
+
streamlit==1.24.0
|
| 3 |
+
openai>=1.0.0
|
| 4 |
+
python-dotenv>=1.0.0
|
| 5 |
+
|
| 6 |
+
# Additional dependencies
|
| 7 |
+
numpy>=1.24.3
|
| 8 |
+
pandas>=2.0.0
|
| 9 |
+
tqdm>=4.66.0
|
| 10 |
+
|
| 11 |
+
# Flask dependencies
|
| 12 |
+
flask==2.3.3
|
| 13 |
+
pytest==7.4.0
|
| 14 |
+
black==23.7.0
|
| 15 |
+
flake8==6.1.0
|