提交 81b0c3bc 编写于 作者: W weixin_41863029

Fri Dec 1 16:01:00 CST 2023 inscode

上级 0520122c
import streamlit as st
from streamlit_option_menu import option_menu
import requests
import base64
# 设置Streamlit应用程序的标题
st.set_page_config(page_title="app name", layout="wide")
def run_c_code(code):
endpoint = "https://api.jdoodle.com/v1/execute"
client_id = "your_client_id"
client_secret = "your_client_secret"
language = "c"
version_index = "0"
data = {
"clientId": client_id,
"clientSecret": client_secret,
"script": code,
"language": language,
"versionIndex": version_index
}
r = requests.post(url=endpoint, json=data)
return r.json()
menu1="菜单1"
menu2="菜单2"
def get_shareable_link(code):
code_bytes = code.encode('ascii')
encoded_code = base64.b64encode(code_bytes).decode('ascii')
link = f"https://share.streamlit.io/?code={encoded_code}"
return link
with st.sidebar:
menu = option_menu("菜单", [menu1, menu2],
icons=['house', "list-task"],
menu_icon="cast", default_index=0)
st.title("C Code Editor and Runner")
st.write("Enter your C code below and run it directly in the browser!")
def main():
code = st.text_area("Enter your code here", height=500, key="code_area")
run_clicked = st.button("Run Code")
if run_clicked:
with st.spinner("Running your code..."):
result = run_c_code(code)
st.write("Output:")
st.code(result['output'])
st.write("Errors:")
st.code(result['stderr'])
if menu == menu1:
st.subheader(f"{menu1}")
if menu == menu2:
st.subheader(f"{menu2}")
if __name__ == '__main__':
main()
share_clicked = st.button("Get Shareable Link")
if share_clicked:
link = get_shareable_link(code)
st.write("Share this link to share your code with others:")
st.write(link)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册