Update app.py
Browse files6 unmodified lines7891011121319 unmodified lines333435363738394041426 unmodified lines# Introductionst.write("""### Generate Code Snippets with AIEnter a programming-related prompt, and the AI will generate a code snippet for you.""")# Input box for user query19 unmodified lineswith st.spinner("Generating code..."):try:# Generate code using the modelresult = model(user_input, max_length=100, num_return_sequences=1)generated_code = result[0]["generated_text"]# Display the outputst.code(generated_code, language="python")except Exception as e:st.error(f"An error occurred: {e}")6 unmodified lines7891011121319 unmodified lines33343536373839404142434445464748495051525354556 unmodified lines# Introductionst.write("""### Generate Code Snippets with AIEnter a programming-related prompt, and the AI will generate a code snippet with explanatory comments.""")# Input box for user query19 unmodified lineswith st.spinner("Generating code..."):try:# Generate code using the modelresult = model(user_input, max_length=200, num_return_sequences=1)generated_text = result[0]["generated_text"]# Split comments and code for better presentationlines = generated_text.split("\n")comments = [line for line in lines if line.strip().startswith("#")]code = [line for line in lines if not line.strip().startswith("#")]# Display comments as markdownif comments:st.subheader("Comments")for comment in comments:st.markdown(comment)# Display code as Python syntax-highlighted blockif code:st.subheader("Code")st.code("\n".join(code), language="python")except Exception as e:st.error(f"An error occurred: {e}")
app.py+18-5