Update app.py
Browse files
app.py
CHANGED
@@ -4,8 +4,6 @@ import openai
|
|
4 |
import faiss
|
5 |
import os
|
6 |
import numpy as np
|
7 |
-
from sklearn.feature_extraction.text import TfidfVectorizer
|
8 |
-
from sklearn.metrics.pairwise import cosine_similarity
|
9 |
from io import StringIO
|
10 |
|
11 |
# Function to extract text from a PDF file
|
@@ -120,43 +118,10 @@ if openai_api_key:
|
|
120 |
|
121 |
# Display the response in Streamlit (Intelligent Reply)
|
122 |
st.write("### Intelligent Reply:")
|
123 |
-
st.
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
# Code generation prompt input
|
129 |
-
code_prompt = st.text_area("Describe the code you want to generate:",
|
130 |
-
"e.g., Write a Python program that generates Fibonacci numbers.")
|
131 |
-
|
132 |
-
if st.button("Generate Code"):
|
133 |
-
if code_prompt:
|
134 |
-
with st.spinner("Generating code..."):
|
135 |
-
# Generate code using GPT-4
|
136 |
-
generated_code = generate_code_from_prompt(code_prompt)
|
137 |
-
|
138 |
-
# Clean the generated code to ensure only code is saved (removing comments or additional text)
|
139 |
-
clean_code = "\n".join([line for line in generated_code.splitlines() if not line.strip().startswith("#")])
|
140 |
-
|
141 |
-
# Save the clean code to a file
|
142 |
-
save_code_to_file(clean_code)
|
143 |
-
|
144 |
-
# Display the generated code
|
145 |
-
st.write("### Generated Code:")
|
146 |
-
st.code(clean_code, language="python")
|
147 |
-
|
148 |
-
# Provide a download link for the generated code
|
149 |
-
with open("generated_code.txt", "w") as f:
|
150 |
-
f.write(clean_code)
|
151 |
-
|
152 |
-
st.download_button(
|
153 |
-
label="Download Generated Code",
|
154 |
-
data=open("generated_code.txt", "rb").read(),
|
155 |
-
file_name="generated_code.txt",
|
156 |
-
mime="text/plain"
|
157 |
-
)
|
158 |
-
else:
|
159 |
-
st.error("Please provide a prompt to generate the code.")
|
160 |
|
161 |
elif mode == "AI Chatbot Tutor":
|
162 |
st.header("AI Chatbot Tutor")
|
@@ -180,6 +145,10 @@ if openai_api_key:
|
|
180 |
bot_response = chat_with_bot(user_query)
|
181 |
st.write(f"### AI Response: {bot_response}")
|
182 |
|
|
|
|
|
|
|
|
|
183 |
elif mode == "AI Study Notes & Summaries":
|
184 |
st.header("AI Study Notes & Summaries")
|
185 |
|
@@ -200,4 +169,7 @@ if openai_api_key:
|
|
200 |
|
201 |
# Display the summary
|
202 |
st.write("### AI-Generated Summary:")
|
203 |
-
st.
|
|
|
|
|
|
|
|
4 |
import faiss
|
5 |
import os
|
6 |
import numpy as np
|
|
|
|
|
7 |
from io import StringIO
|
8 |
|
9 |
# Function to extract text from a PDF file
|
|
|
118 |
|
119 |
# Display the response in Streamlit (Intelligent Reply)
|
120 |
st.write("### Intelligent Reply:")
|
121 |
+
st.text_area("Response:", response_content, height=300)
|
122 |
+
|
123 |
+
# Copy button
|
124 |
+
st.button("Copy Response", on_click=lambda: st.text_area("Copy the response", response_content, height=300))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
elif mode == "AI Chatbot Tutor":
|
127 |
st.header("AI Chatbot Tutor")
|
|
|
145 |
bot_response = chat_with_bot(user_query)
|
146 |
st.write(f"### AI Response: {bot_response}")
|
147 |
|
148 |
+
# Copy button
|
149 |
+
st.text_area("Copy the response", bot_response, height=300)
|
150 |
+
st.button("Copy Response", on_click=lambda: st.text_area("Copy the response", bot_response, height=300))
|
151 |
+
|
152 |
elif mode == "AI Study Notes & Summaries":
|
153 |
st.header("AI Study Notes & Summaries")
|
154 |
|
|
|
169 |
|
170 |
# Display the summary
|
171 |
st.write("### AI-Generated Summary:")
|
172 |
+
st.text_area("Summary:", summary, height=300)
|
173 |
+
|
174 |
+
# Copy button
|
175 |
+
st.button("Copy Summary", on_click=lambda: st.text_area("Copy the summary", summary, height=300))
|