shukdevdatta123 commited on
Commit
3a7c226
·
verified ·
1 Parent(s): 4287e6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -31
app.py CHANGED
@@ -6,8 +6,6 @@ import os
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
- from docx import Document # New import for working with docx files
11
 
12
  # Function to extract text from a PDF file
13
  def extract_text_from_pdf(pdf_file):
@@ -28,23 +26,6 @@ def search_similar(query_embedding, index, stored_texts, top_k=3):
28
  results = [(stored_texts[i], distances[0][idx]) for idx, i in enumerate(indices[0])]
29
  return results
30
 
31
- # Function to generate a docx file with the response content
32
- def generate_docx(response_content):
33
- doc = Document()
34
-
35
- # Adding title and response to the docx
36
- doc.add_heading('Course Query Response', 0)
37
- doc.add_heading('Answer:', level=1)
38
- doc.add_paragraph(response_content)
39
-
40
- # Save the document to a byte stream to allow for download in Streamlit
41
- from io import BytesIO
42
- doc_io = BytesIO()
43
- doc.save(doc_io)
44
- doc_io.seek(0)
45
-
46
- return doc_io
47
-
48
  # Streamlit app starts here
49
  st.title("Course Query Assistant")
50
 
@@ -100,7 +81,7 @@ if openai_api_key:
100
 
101
  # Get the GPT-4 response
102
  response = openai.ChatCompletion.create(
103
- model="gpt-4o-mini", # Update to GPT-4 (or your desired model)
104
  messages=[{"role": "user", "content": modified_prompt}]
105
  )
106
 
@@ -110,14 +91,3 @@ if openai_api_key:
110
  # Display the response in Streamlit (Intelligent Reply)
111
  st.write("### Intelligent Reply:")
112
  st.write(response_content)
113
-
114
- # Generate a docx file based on the exact response content
115
- docx_file = generate_docx(response_content)
116
-
117
- # Provide the download button for the .docx file
118
- st.download_button(
119
- label="Download Response as DOCX",
120
- data=docx_file,
121
- file_name="course_query_response.docx",
122
- mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
123
- )
 
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):
 
26
  results = [(stored_texts[i], distances[0][idx]) for idx, i in enumerate(indices[0])]
27
  return results
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  # Streamlit app starts here
30
  st.title("Course Query Assistant")
31
 
 
81
 
82
  # Get the GPT-4 response
83
  response = openai.ChatCompletion.create(
84
+ model="gpt-4", # Update to GPT-4 (or your desired model)
85
  messages=[{"role": "user", "content": modified_prompt}]
86
  )
87
 
 
91
  # Display the response in Streamlit (Intelligent Reply)
92
  st.write("### Intelligent Reply:")
93
  st.write(response_content)