shukdevdatta123 commited on
Commit
ca29ecb
·
verified ·
1 Parent(s): 7d20066

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -6,6 +6,7 @@ import os
6
  import numpy as np
7
  from sklearn.feature_extraction.text import TfidfVectorizer
8
  from sklearn.metrics.pairwise import cosine_similarity
 
9
 
10
  # Function to extract text from a PDF file
11
  def extract_text_from_pdf(pdf_file):
@@ -28,6 +29,9 @@ def search_similar(query_embedding, index, stored_texts, top_k=3):
28
 
29
  # Function to generate HTML with nice styling
30
  def generate_html(response_content):
 
 
 
31
  html_template = f"""
32
  <!DOCTYPE html>
33
  <html lang="en">
@@ -77,7 +81,7 @@ def generate_html(response_content):
77
  <h1>Course Query Response</h1>
78
  <div class="response">
79
  <h3>Answer:</h3>
80
- <p>{response_content}</p>
81
  </div>
82
  <footer>
83
  <p>Generated by Course Query Assistant</p>
@@ -150,7 +154,7 @@ if openai_api_key:
150
  # Get the response content
151
  response_content = response['choices'][0]['message']['content']
152
 
153
- # Display the response in Streamlit
154
  st.write("### Intelligent Reply:")
155
  st.write(response_content)
156
 
 
6
  import numpy as np
7
  from sklearn.feature_extraction.text import TfidfVectorizer
8
  from sklearn.metrics.pairwise import cosine_similarity
9
+ import html
10
 
11
  # Function to extract text from a PDF file
12
  def extract_text_from_pdf(pdf_file):
 
29
 
30
  # Function to generate HTML with nice styling
31
  def generate_html(response_content):
32
+ # Escape any HTML special characters to prevent unwanted rendering issues
33
+ safe_content = html.escape(response_content)
34
+
35
  html_template = f"""
36
  <!DOCTYPE html>
37
  <html lang="en">
 
81
  <h1>Course Query Response</h1>
82
  <div class="response">
83
  <h3>Answer:</h3>
84
+ <p>{safe_content}</p>
85
  </div>
86
  <footer>
87
  <p>Generated by Course Query Assistant</p>
 
154
  # Get the response content
155
  response_content = response['choices'][0]['message']['content']
156
 
157
+ # Display the response in Streamlit (Intelligent Reply)
158
  st.write("### Intelligent Reply:")
159
  st.write(response_content)
160