kinely commited on
Commit
24d7505
·
verified ·
1 Parent(s): 546bbed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -14
app.py CHANGED
@@ -2,7 +2,11 @@ import streamlit as st
2
  from transformers import pipeline
3
  from PyPDF2 import PdfReader
4
  from sentence_transformers import SentenceTransformer, util
 
 
 
5
  import os
 
6
 
7
  # Load Hugging Face model (e.g., FLAN-T5 or GPT-like model)
8
  @st.cache_resource
@@ -34,6 +38,37 @@ def get_relevant_content(query, texts, embedder, embeddings):
34
  best_idx = scores.argmax().item()
35
  return texts[best_idx]
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  # Streamlit UI
38
  def main():
39
  st.title("Educational Assistant Chatbot")
@@ -64,7 +99,7 @@ def main():
64
  response = model(f"Question: {user_query} Context: {relevant_content}", max_length=200)
65
  st.success(response[0]['generated_text'])
66
 
67
- # Profile creation
68
  st.markdown("### Create a Student Profile")
69
  name = st.text_input("Name:")
70
  email = st.text_input("Email:")
@@ -74,20 +109,31 @@ def main():
74
  career_goal = st.text_area("Career Goals:")
75
  visa_query = st.text_area("Visa Concerns or Questions:")
76
 
 
 
 
 
 
 
77
  if st.button("Submit Profile"):
78
- profile = f"""
79
- Name: {name}
80
- Email: {email}
81
- Contact Number: {contact_number}
82
- Level of Study: {study_level}
83
- Field of Interest: {field_of_interest}
84
- Career Goals: {career_goal}
85
- Visa Queries: {visa_query}
86
- """
87
- # Simulate email sending (for simplicity, just display the profile)
88
- st.markdown("### Profile Summary")
89
- st.code(profile)
90
- st.success(f"Profile submitted to {email_to_send}!")
 
 
 
 
 
91
 
92
  if __name__ == "__main__":
93
  main()
 
2
  from transformers import pipeline
3
  from PyPDF2 import PdfReader
4
  from sentence_transformers import SentenceTransformer, util
5
+ import smtplib
6
+ from email.mime.text import MIMEText
7
+ from email.mime.multipart import MIMEMultipart
8
  import os
9
+ import random
10
 
11
  # Load Hugging Face model (e.g., FLAN-T5 or GPT-like model)
12
  @st.cache_resource
 
38
  best_idx = scores.argmax().item()
39
  return texts[best_idx]
40
 
41
+ # Email functionality
42
+ def send_email(to_email, subject, body):
43
+ try:
44
+ sender_email = "your-email@example.com" # Replace with your email
45
+ sender_password = "your-email-password" # Replace with your email password
46
+ smtp_server = "smtp.gmail.com" # Adjust for your email provider
47
+ smtp_port = 587
48
+
49
+ # Set up the email
50
+ msg = MIMEMultipart()
51
+ msg['From'] = sender_email
52
+ msg['To'] = to_email
53
+ msg['Subject'] = subject
54
+ msg.attach(MIMEText(body, 'plain'))
55
+
56
+ # Send the email
57
+ with smtplib.SMTP(smtp_server, smtp_port) as server:
58
+ server.starttls()
59
+ server.login(sender_email, sender_password)
60
+ server.send_message(msg)
61
+ return True
62
+ except Exception as e:
63
+ st.error(f"Failed to send email: {e}")
64
+ return False
65
+
66
+ # CAPTCHA generation
67
+ def generate_captcha():
68
+ num1 = random.randint(1, 9)
69
+ num2 = random.randint(1, 9)
70
+ return num1, num2, num1 + num2
71
+
72
  # Streamlit UI
73
  def main():
74
  st.title("Educational Assistant Chatbot")
 
99
  response = model(f"Question: {user_query} Context: {relevant_content}", max_length=200)
100
  st.success(response[0]['generated_text'])
101
 
102
+ # Profile creation with CAPTCHA
103
  st.markdown("### Create a Student Profile")
104
  name = st.text_input("Name:")
105
  email = st.text_input("Email:")
 
109
  career_goal = st.text_area("Career Goals:")
110
  visa_query = st.text_area("Visa Concerns or Questions:")
111
 
112
+ # CAPTCHA generation
113
+ if "captcha_result" not in st.session_state:
114
+ num1, num2, st.session_state.captcha_result = generate_captcha()
115
+ st.markdown(f"**CAPTCHA: {num1} + {num2} = ?**")
116
+ captcha_input = st.text_input("Enter CAPTCHA Result:")
117
+
118
  if st.button("Submit Profile"):
119
+ if int(captcha_input) != st.session_state.captcha_result:
120
+ st.error("Invalid CAPTCHA. Please try again.")
121
+ else:
122
+ profile = f"""
123
+ Name: {name}
124
+ Email: {email}
125
+ Contact Number: {contact_number}
126
+ Level of Study: {study_level}
127
+ Field of Interest: {field_of_interest}
128
+ Career Goals: {career_goal}
129
+ Visa Queries: {visa_query}
130
+ """
131
+ # Send profile via email
132
+ email_sent = send_email(email_to_send, "New Student Profile Submission", profile)
133
+ if email_sent:
134
+ st.success(f"Profile submitted successfully to {email_to_send}!")
135
+ else:
136
+ st.error("Failed to submit the profile. Please try again later.")
137
 
138
  if __name__ == "__main__":
139
  main()