Update app.py
Browse files
app.py
CHANGED
@@ -49,6 +49,15 @@ def generate_summary(text):
|
|
49 |
)
|
50 |
return response['choices'][0]['message']['content']
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
# Streamlit app starts here
|
53 |
st.title("AI Assistance")
|
54 |
|
@@ -58,9 +67,15 @@ openai_api_key = st.text_input("Enter your OpenAI API key:", type="password")
|
|
58 |
if openai_api_key:
|
59 |
openai.api_key = openai_api_key
|
60 |
|
61 |
-
# Sidebar to toggle between Course Query Assistant
|
62 |
st.sidebar.title("Select Mode")
|
63 |
-
mode = st.sidebar.radio("Choose an option", (
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
if mode == "Course Query Assistant":
|
66 |
st.header("Course Query Assistant")
|
@@ -200,4 +215,33 @@ if openai_api_key:
|
|
200 |
|
201 |
# Display the summary
|
202 |
st.write("### AI-Generated Summary:")
|
203 |
-
st.write(summary)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
)
|
50 |
return response['choices'][0]['message']['content']
|
51 |
|
52 |
+
# Function to fix bugs in code
|
53 |
+
def fix_code_bugs(buggy_code, model="gpt-4o-mini"):
|
54 |
+
prompt = f"The following code has bugs or issues. Please identify and fix the problems. If possible, provide explanations for the changes made.\n\nBuggy Code:\n{buggy_code}\n\nFixed Code:"
|
55 |
+
response = openai.ChatCompletion.create(
|
56 |
+
model=model,
|
57 |
+
messages=[{"role": "user", "content": prompt}]
|
58 |
+
)
|
59 |
+
return response['choices'][0]['message']['content']
|
60 |
+
|
61 |
# Streamlit app starts here
|
62 |
st.title("AI Assistance")
|
63 |
|
|
|
67 |
if openai_api_key:
|
68 |
openai.api_key = openai_api_key
|
69 |
|
70 |
+
# Sidebar to toggle between Course Query Assistant, Code Generator, Bug Fixer, etc.
|
71 |
st.sidebar.title("Select Mode")
|
72 |
+
mode = st.sidebar.radio("Choose an option", (
|
73 |
+
"Course Query Assistant",
|
74 |
+
"Code Generator",
|
75 |
+
"AI Chatbot Tutor",
|
76 |
+
"AI Study Notes & Summaries",
|
77 |
+
"Code Bug Fixer"
|
78 |
+
))
|
79 |
|
80 |
if mode == "Course Query Assistant":
|
81 |
st.header("Course Query Assistant")
|
|
|
215 |
|
216 |
# Display the summary
|
217 |
st.write("### AI-Generated Summary:")
|
218 |
+
st.write(summary)
|
219 |
+
|
220 |
+
elif mode == "Code Bug Fixer":
|
221 |
+
st.header("Code Bug Fixer")
|
222 |
+
|
223 |
+
# User input for buggy code
|
224 |
+
buggy_code = st.text_area("Enter your buggy code here:")
|
225 |
+
|
226 |
+
if st.button("Fix Code"):
|
227 |
+
if buggy_code:
|
228 |
+
with st.spinner("Fixing code..."):
|
229 |
+
# Fix bugs using GPT-4
|
230 |
+
fixed_code = fix_code_bugs(buggy_code)
|
231 |
+
|
232 |
+
# Display the fixed code
|
233 |
+
st.write("### Fixed Code:")
|
234 |
+
st.code(fixed_code, language="python")
|
235 |
+
|
236 |
+
# Provide a download link for the fixed code
|
237 |
+
with open("fixed_code.txt", "w") as f:
|
238 |
+
f.write(fixed_code)
|
239 |
+
|
240 |
+
st.download_button(
|
241 |
+
label="Download Fixed Code",
|
242 |
+
data=open("fixed_code.txt", "rb").read(),
|
243 |
+
file_name="fixed_code.txt",
|
244 |
+
mime="text/plain"
|
245 |
+
)
|
246 |
+
else:
|
247 |
+
st.error("Please enter some buggy code to fix.")
|