Spaces:
Runtime error
Runtime error
skolvankar
commited on
Commit
•
d4e1638
1
Parent(s):
31ac90d
Add application file
Browse files
app.py
CHANGED
@@ -27,6 +27,36 @@ sheet_name = "Shortlisted Courses" # Replace with the actual sheet name
|
|
27 |
# Read the Excel file into a Pandas DataFrame
|
28 |
courses_df = pd.read_csv(excel_file_path)
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
# Function to recommend courses based on user input using GPT and TF-IDF
|
31 |
def recommend_courses(user_skill, ed_qual):
|
32 |
# Combine user's input into a single string for TF-IDF
|
@@ -72,44 +102,6 @@ def recommend_courses(user_skill, ed_qual):
|
|
72 |
|
73 |
return final_recommendations_html
|
74 |
|
75 |
-
# Create a TF-IDF vectorizer
|
76 |
-
tfidf_vectorizer = TfidfVectorizer(stop_words='english')
|
77 |
-
tfidf_matrix = tfidf_vectorizer.fit_transform(courses_df['Course Name'].fillna(''))
|
78 |
-
|
79 |
-
user_skill = "psychology"
|
80 |
-
|
81 |
-
ed_qual = "B.Tech/B.Sc"
|
82 |
-
|
83 |
-
html = recommend_courses(user_skill, ed_qual)
|
84 |
-
|
85 |
-
html
|
86 |
-
|
87 |
-
def html_coversion(gpt_content):
|
88 |
-
|
89 |
-
# Provided data in text format
|
90 |
-
data_text = gpt_content
|
91 |
-
|
92 |
-
# Extract course details using a modified regular expression
|
93 |
-
courses = re.findall(r'(\d+)\. (.*?):\n\s*- Course Link: \[([^\]]+)\]\(([^)]+)\)\n\s*- Description: ([^\n]+)', data_text)
|
94 |
-
|
95 |
-
# Process each tuple to remove the second occurrence of the course link
|
96 |
-
processed_courses = []
|
97 |
-
for course_tuple in courses:
|
98 |
-
# Find the index of the second occurrence of the course link
|
99 |
-
index_of_second_occurrence = course_tuple.index(course_tuple[2], course_tuple.index(course_tuple[2]) + 1)
|
100 |
-
# Remove the second occurrence of the course link from the tuple
|
101 |
-
processed_tuple = course_tuple[:index_of_second_occurrence] + course_tuple[index_of_second_occurrence + 1:]
|
102 |
-
processed_courses.append(processed_tuple)
|
103 |
-
|
104 |
-
# Convert the processed list of tuples into a DataFrame
|
105 |
-
df = pd.DataFrame(processed_courses, columns=['Sr No', 'Course Name', 'Course Link', 'Description'])
|
106 |
-
|
107 |
-
# Convert the DataFrame to an HTML table
|
108 |
-
html_table = df.to_html(index=False, escape=False)
|
109 |
-
|
110 |
-
# Print or save the HTML table
|
111 |
-
return html_table
|
112 |
-
|
113 |
# Gradio Interface with dynamically generated dropdown options
|
114 |
iface = gr.Interface(
|
115 |
fn=recommend_courses,
|
|
|
27 |
# Read the Excel file into a Pandas DataFrame
|
28 |
courses_df = pd.read_csv(excel_file_path)
|
29 |
|
30 |
+
# Create a TF-IDF vectorizer
|
31 |
+
tfidf_vectorizer = TfidfVectorizer(stop_words='english')
|
32 |
+
tfidf_matrix = tfidf_vectorizer.fit_transform(courses_df['Course Name'].fillna(''))
|
33 |
+
|
34 |
+
def html_coversion(gpt_content):
|
35 |
+
|
36 |
+
# Provided data in text format
|
37 |
+
data_text = gpt_content
|
38 |
+
|
39 |
+
# Extract course details using a modified regular expression
|
40 |
+
courses = re.findall(r'(\d+)\. (.*?):\n\s*- Course Link: \[([^\]]+)\]\(([^)]+)\)\n\s*- Description: ([^\n]+)', data_text)
|
41 |
+
|
42 |
+
# Process each tuple to remove the second occurrence of the course link
|
43 |
+
processed_courses = []
|
44 |
+
for course_tuple in courses:
|
45 |
+
# Find the index of the second occurrence of the course link
|
46 |
+
index_of_second_occurrence = course_tuple.index(course_tuple[2], course_tuple.index(course_tuple[2]) + 1)
|
47 |
+
# Remove the second occurrence of the course link from the tuple
|
48 |
+
processed_tuple = course_tuple[:index_of_second_occurrence] + course_tuple[index_of_second_occurrence + 1:]
|
49 |
+
processed_courses.append(processed_tuple)
|
50 |
+
|
51 |
+
# Convert the processed list of tuples into a DataFrame
|
52 |
+
df = pd.DataFrame(processed_courses, columns=['Sr No', 'Course Name', 'Course Link', 'Description'])
|
53 |
+
|
54 |
+
# Convert the DataFrame to an HTML table
|
55 |
+
html_table = df.to_html(index=False, escape=False)
|
56 |
+
|
57 |
+
# Print or save the HTML table
|
58 |
+
return html_table
|
59 |
+
|
60 |
# Function to recommend courses based on user input using GPT and TF-IDF
|
61 |
def recommend_courses(user_skill, ed_qual):
|
62 |
# Combine user's input into a single string for TF-IDF
|
|
|
102 |
|
103 |
return final_recommendations_html
|
104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
# Gradio Interface with dynamically generated dropdown options
|
106 |
iface = gr.Interface(
|
107 |
fn=recommend_courses,
|