Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,61 +1,47 @@
|
|
| 1 |
-
from transformers import
|
| 2 |
-
import gradio as gr
|
| 3 |
-
import torch
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
examples = [["How are you?"]]
|
| 8 |
-
|
| 9 |
-
tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-large")
|
| 10 |
-
model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-large")
|
| 11 |
|
| 12 |
# Course information
|
| 13 |
course_info = {
|
| 14 |
-
"
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
"Creative Industries": ["Animation", "Photography", "Creative Writing", "Film and Television", "etc."]
|
| 25 |
-
}
|
| 26 |
}
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
description=description,
|
| 57 |
-
examples=examples,
|
| 58 |
-
inputs=["text", "state"],
|
| 59 |
-
outputs=["chatbot", "state"],
|
| 60 |
-
theme="finlaymacklon/boxy_violet",
|
| 61 |
-
).launch()
|
|
|
|
| 1 |
+
from transformers import pipeline
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
# Load conversational pipeline
|
| 4 |
+
conversation = pipeline("conversational")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Course information
|
| 7 |
course_info = {
|
| 8 |
+
"Engineering": ["Civil Engineering", "Mechanical Engineering", "Electrical Engineering", "Software Engineering", "etc."],
|
| 9 |
+
"Information Technology": ["Computer Science", "Information Systems", "Cybersecurity", "Data Science", "etc."],
|
| 10 |
+
"Business": ["Business Administration", "Accounting", "Finance", "Marketing", "Management", "etc."],
|
| 11 |
+
"Health Sciences": ["Nursing", "Pharmacy", "Health Information Management", "Public Health", "etc."],
|
| 12 |
+
"Design and Architecture": ["Architecture", "Industrial Design", "Visual Communication", "etc."],
|
| 13 |
+
"Science": ["Environmental Science", "Biotechnology", "Chemistry", "Physics", "etc."],
|
| 14 |
+
"Law": ["Law", "Legal Studies", "etc."],
|
| 15 |
+
"Arts and Social Sciences": ["Communication", "Education", "International Studies", "Sociology", "etc."],
|
| 16 |
+
"Built Environment": ["Urban Planning", "Construction Management", "Property Economics", "etc."],
|
| 17 |
+
"Creative Industries": ["Animation", "Photography", "Creative Writing", "Film and Television", "etc."]
|
|
|
|
|
|
|
| 18 |
}
|
| 19 |
|
| 20 |
+
# Function to generate response using conversational AI
|
| 21 |
+
def generate_response(user_input):
|
| 22 |
+
return conversation(user_input)[0]['generated_text']
|
| 23 |
+
|
| 24 |
+
# Function to list courses based on category
|
| 25 |
+
def list_courses(input_text):
|
| 26 |
+
for category, courses in course_info.items():
|
| 27 |
+
if category.lower() in input_text:
|
| 28 |
+
return f"Under {category}, we offer: {', '.join(courses)}"
|
| 29 |
+
return "I'm sorry, I couldn't find any courses matching that."
|
| 30 |
+
|
| 31 |
+
# Main function to interact with the chatbot
|
| 32 |
+
def chat():
|
| 33 |
+
print("Welcome to the Course Chatbot! Ask me about available courses or say goodbye to exit.")
|
| 34 |
+
while True:
|
| 35 |
+
user_input = input("You: ")
|
| 36 |
+
if user_input.lower() in ["exit", "quit", "goodbye"]:
|
| 37 |
+
print("Goodbye!")
|
| 38 |
+
break
|
| 39 |
+
else:
|
| 40 |
+
if "courses" in user_input:
|
| 41 |
+
bot_response = list_courses(user_input)
|
| 42 |
+
else:
|
| 43 |
+
bot_response = generate_response(user_input)
|
| 44 |
+
print("Bot:", bot_response)
|
| 45 |
+
|
| 46 |
+
if __name__ == "__main__":
|
| 47 |
+
chat()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|