Download app.py from Pezh/bmm: direct link, hf CLI and curl.
- Browser
- Download file 15.7 kB
-
https://huggingface.co/spaces/Pezh/bmm/resolve/main/app.py
- Command line
-
hf download hf://spaces/Pezh/bmm/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Pezh/bmm/resolve/main/app.py
15.7 kB
| import streamlit as st | |
| import streamlit.components.v1 as components | |
| # Example HTML | |
| html_content = """ | |
| <html dir='rtl'> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> | |
| <link rel="preload" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2?v=4.7.0" as="font" type="font/woff2" crossorigin="anonymous"> | |
| <body> | |
| <!-- ... Your HTML and CSS --> | |
| <div> | |
| <label for="n2">شرح حال مریض را بنویسید</label><br> | |
| <input type="text" name="" value="" id="n" placeholder='حداقل : بیمار خانم 32 ساله حامله 29 هفته مولتی پار با شکایت خونریزی از واژن آمده است'><br> | |
| </div><br> | |
| <div> | |
| <label>سوابق</label><br> | |
| <input type="text" name="" value="" placeholder=' بیماریها: فشار خون، MI، ، آسم، اسکیزوفرنی، کمکاری تیرویید، ایدز...'><br> | |
| <input type="" name="" value="" placeholder='جراحی : آپاندکتومی، تعویض مفصل زانو، CABG، آسپیرسیون کیست هیداتید...'><br> | |
| <input type="" name="" value="" placeholder='داروها : وارفارین، لیتیوم، دیگوکسین، آهن، آمی تریپتیلین...'><br> | |
| <input type="text" name="" value="" placeholder='سوشیال : سیگار، قلیان، تریاک، کراک...'><br> | |
| </div><br> | |
| <div> | |
| <label for="">نشانه</label> | |
| <button type="" class='button-17' onclick='ado()'><i class="fa fa-plus" style="font-size:19px;color:#1640D6;"></i></button><br> | |
| <div> | |
| <div id='divo'> | |
| <input type="text" name="" value="" placeholder='یه مربض اومده با فشار خون بالا که صورتش انگار پف کرده، عکسشو میدم بگو این تو چه بیماریه!'><br> | |
| <input type="file" id="imageFileInput" accept="image/*"><br> | |
| </div> | |
| <div> | |
| <button type="" class='button-18'>Report</button><br> | |
| <p></p><br> | |
| </div> | |
| </div> | |
| </div><br> | |
| <div> | |
| <label for="">پوست</label> | |
| <button type="" class='button-17' onclick='add3()'><i class="fa fa-plus" style="font-size:19px;color:#1640D6;"></i></button><br> | |
| <div> | |
| <div id='div-3'> | |
| <input type="text" name="" value="" placeholder='پاپول هایپرکراتوز چرب در نواحی سبورئیک به همراه ناهنجاری ناخن ها و تعداد زیادی پاپول کوچک در سقف دهان'><br> | |
| <input type="file" id="imageFileInput" accept="image/*"><br> | |
| </div> | |
| <div> | |
| <button type="" class='button-18'>Report</button><br> | |
| <p id='kll'></p><br> | |
| </div> | |
| </div> | |
| </div><br> | |
| <div> | |
| <label for="">آزمایشات</label> | |
| <button type="" class='button-17' onclick='add4()'><i class="fa fa-plus" style="font-size:19px;color:#1640D6;"></i></button><br> | |
| <div> | |
| <div id='div-4'> | |
| <input type="text" name="" value="" placeholder='مثال : U/A, CBC, LFT...'><br> | |
| <input type="file" id="imageFileInp" accept="image/*"><br> | |
| </div> | |
| <div> | |
| <button type="" class='button-18' onclick='per()'>Hooch</button><br> | |
| <p id='pp'></p><br> | |
| </div> | |
| </div> | |
| </div><br> | |
| <label for="">رادیولوژی</label> | |
| <button type="" class='button-17' onclick='add1()'><i class="fa fa-plus" style="font-size:19px;color:#1640D6;"></i></button><br> | |
| <div> | |
| <div id='div-1'> | |
| <input type="text" name="" value="" placeholder='سی تی اسکن شکم-لگن با کنتراست خوراکی و وریدی'><br> | |
| <input type="file" id="imageFileInput" accept="image/*"><br> | |
| </div> | |
| <div> | |
| <button type="" class='button-18'>Report</button><br> | |
| <p></p><br> | |
| </div> | |
| </div> | |
| <div> | |
| <label for="">پاتولوژی</label> | |
| <button type="" class='button-17' onclick='add5()'><i class="fa fa-plus" style="font-size:19px;color:#1640D6;"></i></button><br> | |
| <div> | |
| <div id='div-5'> | |
| <input type="text" name="" value="" placeholder='اکسیژن بافت پانکراس در آقای 72 ساله با شکایت زردی و کاهش وزن'><br> | |
| <input type="file" id="imageFileInput" accept="image/*"><br> | |
| </div> | |
| <div> | |
| <button type="" class='button-18'>Report</button><br> | |
| <p></p><br> | |
| </div> | |
| </div> | |
| </div> | |
| <div> | |
| <button type="" class='button-18'>Diagnosis (and ddx)</button> | |
| <button type="" class='button-18'>Rx (medical orders)</button> | |
| <button type="" id="calculateButton" class='button-18'>احتیاطات دارویی</button><br> | |
| <p></p> | |
| <p></p> | |
| <p></p> | |
| </div> | |
| </div> | |
| </body> | |
| </html> | |
| """ | |
| # Example CSS | |
| css_content = """ | |
| <style> | |
| body { | |
| text-align: center; | |
| overflow: auto; | |
| } | |
| input { | |
| width: 60%; | |
| padding: 16px 20px; | |
| border: none; | |
| border-radius: 10px; | |
| background-color: #f1f1f1; | |
| margin:3px; | |
| position:relative | |
| } | |
| p { | |
| background-color: #f1f1f1; | |
| border-radius: 4px; | |
| padding: 5px; | |
| display: none; | |
| width: 60%; /* Aligns with the width of the input elements above */ | |
| margin-right: 20%; /* Adjust to position your element correctly (since it's RTL) */ | |
| margin-left: auto; | |
| text-align: justify; | |
| /* centers the p element and provides spacing above and below */ /* or as per your design requirement */ | |
| } | |
| label { | |
| font-size: 18px; | |
| margin-bottom: 12px; | |
| right:20%; | |
| position: absolute | |
| } | |
| .button-18 { | |
| align-items: center; | |
| appearance: none; | |
| background-color: #1640D6; | |
| border-radius: 19px; | |
| border-style: none; | |
| box-shadow: rgba(0, 0, 0, .2) 0 3px 5px -1px,rgba(0, 0, 0, .14) 0 6px 10px 0,rgba(0, 0, 0, .12) 0 1px 18px 0; | |
| box-sizing: border-box; | |
| color: white; | |
| cursor: pointer; | |
| display: inline-flex; | |
| fill: currentcolor; | |
| font-family: "Google Sans",Roboto,Arial,sans-serif; | |
| font-size: 14px; | |
| font-weight: 500; | |
| height: 40px; | |
| justify-content: center; | |
| letter-spacing: .25px; | |
| line-height: normal; | |
| max-width: 100%; | |
| overflow: visible; | |
| padding: 2px 24px; | |
| position: relative; | |
| text-align: center; | |
| text-transform: none; | |
| user-select: none; | |
| -webkit-user-select: none; | |
| touch-action: manipulation; | |
| width: auto; | |
| will-change: transform,opacity; | |
| z-index: 0; | |
| margin-bottom: 5px | |
| } | |
| .button-18:hover { | |
| background: #11009E; | |
| height: 42px; | |
| } | |
| .button-18:active { | |
| box-shadow: 0 4px 4px 0 rgb(60 64 67 / 30%), 0 8px 12px 6px rgb(60 64 67 / 15%); | |
| outline: none; | |
| } | |
| .button-18:focus { | |
| outline: none; | |
| border: 2px solid #4285f4; | |
| } | |
| .button-17 { | |
| align-items: center; | |
| appearance: none; | |
| background-color: #fff; | |
| right:28%; | |
| border-radius: 24px; | |
| border-style: none; | |
| box-shadow: rgba(0, 0, 0, .2) 0 3px 5px -1px,rgba(0, 0, 0, .14) 0 6px 10px 0,rgba(0, 0, 0, .12) 0 1px 18px 0; | |
| box-sizing: border-box; | |
| color: #3c4043; | |
| cursor: pointer; | |
| display: inline-flex; | |
| fill: currentcolor; | |
| font-family: "Google Sans",Roboto,Arial,sans-serif; | |
| font-size: 14px; | |
| font-weight: 500; | |
| height: 38px; | |
| justify-content: center; | |
| letter-spacing: .25px; | |
| line-height: normal; | |
| max-width: 100%; | |
| overflow: visible; | |
| padding: 2px 24px; | |
| position: relative; | |
| text-align: center; | |
| text-transform: none; | |
| user-select: none; | |
| -webkit-user-select: none; | |
| touch-action: manipulation; | |
| width: auto; | |
| will-change: transform,opacity; | |
| z-index: 0; | |
| margin-bottom: 10px | |
| } | |
| .button-17:hover { | |
| background: #F6F9FE; | |
| color: #174ea6; | |
| height: 40px; | |
| } | |
| .button-17:active { | |
| box-shadow: 0 4px 4px 0 rgb(60 64 67 / 30%), 0 8px 12px 6px rgb(60 64 67 / 15%); | |
| outline: none; | |
| } | |
| .button-17:focus { | |
| outline: none; | |
| border: 2px solid #4285f4; | |
| } | |
| .button-17:not(:disabled) { | |
| box-shadow: rgba(60, 64, 67, .3) 0 1px 3px 0, rgba(60, 64, 67, .15) 0 4px 8px 3px; | |
| } | |
| .button-17:not(:disabled):hover { | |
| box-shadow: rgba(60, 64, 67, .3) 0 2px 3px 0, rgba(60, 64, 67, .15) 0 6px 10px 4px; | |
| } | |
| .button-17:not(:disabled):focus { | |
| box-shadow: rgba(60, 64, 67, .3) 0 1px 3px 0, rgba(60, 64, 67, .15) 0 4px 8px 3px; | |
| } | |
| .button-17:not(:disabled):active { | |
| box-shadow: rgba(60, 64, 67, .3) 0 4px 4px 0, rgba(60, 64, 67, .15) 0 8px 12px 6px; | |
| } | |
| .button-17:disabled { | |
| box-shadow: rgba(60, 64, 67, .3) 0 1px 3px 0, rgba(60, 64, 67, .15) 0 4px 8px 3px; | |
| } | |
| .add { | |
| background-color: white; /* Green */ | |
| border:3px solid #1640D6; | |
| border-radius: 8px; | |
| margin: 3px; | |
| color: white; | |
| padding: 15px 32px; | |
| text-align: center; | |
| text-decoration: none; | |
| display: inline-block; | |
| font-size: 16px; | |
| position:absolute; | |
| width:4%; | |
| left:19%; | |
| height:4%; | |
| margin-bottom:16px; | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| } | |
| .add:hover { | |
| background-color: #E2DFD2 | |
| } | |
| .dix { | |
| width: 20%; | |
| height: 40%; | |
| padding: 5px; | |
| background-color: #f1f1f1; /* Green */ | |
| border: none; | |
| border-radius: 10px; | |
| text-align: center; | |
| text-decoration: none; | |
| display: inline-block; | |
| } | |
| </style> | |
| """ | |
| # JavaScript code to change paragraph text | |
| js_code = """ | |
| <script> | |
| const fileInput = document.getElementById('imageFileInp'); | |
| const eli = document.getElementById('kll'); | |
| fileInput.addEventListener('change', function() { | |
| if (this.files && this.files.length > 0) { | |
| // If a file is selected, update the paragraph's content | |
| eli.style.display='block' | |
| eli.textContent = 'heyyyyyjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj'; | |
| } | |
| }); | |
| function per() { | |
| var el = document.getElementById('pp'); | |
| el.style.display='block' | |
| el.innerHTML = 'نسبت طلایی یکی از اصول طراحی است که در زیبایی شناسی صورت و تنه نیز بسیار مهم است. این نسبت به این معنی است که نسبت طول به عرض در طراحی باید به گونهای باشد که چشم انسان را جذب کند و زیبایی ظاهری را به وجود آورد. استفاده از نسبتهای طلایی در طراحی صورت و تنه به دلیل داشتن تاثیر بصری بسیار بالا است. رعایت این نسبتهای به گونهای است که چشم انسان را به سمت آن جذب میکند و زیبایی ظاهری را به وجود میآورد. در واقع، رعایت نسبتهای طلایی نه فقط در چهره و تنه، بلکه در طراحی هر چیزی که به چشم میخورد؛ از جمله نقاشی، عکس، معماری و طراحی وب سایت بسیار مهم است. بنابراین، رعایت نسبت طلایی در طراحی صورت و تنه میتواند زیبایی ظاهر را بهبود بخشد و فرد نزدیکتر به این نسبتهای طلایی، به چشم انسان جذابتر و زیباتر به نظر بیاید'; // your content | |
| // Get next sibling element and add a margin-top to create space | |
| var nextElement = el.nextElementSibling; | |
| if (nextElement) { | |
| nextElement.style.marginTop = '20px'; // Adjust the value as required | |
| } | |
| } | |
| function add1() { | |
| document.getElementById('div-1').innerHTML+= ` | |
| <input type="text" name="" value="" placeholder='سی تی اسکن شکم-لگن با کنتراست خوراکی و وریدی'><br> | |
| <input type="file" id="imageFileInput" accept="image/*"><br> | |
| ` | |
| } | |
| function ado() { | |
| document.getElementById('divo').innerHTML=document.getElementById('divo').innerHTML + ` | |
| <input type="text" name="" value="" placeholder='یه مربض اومده با فشار خون بالا که صورتش انگار پف کرده، عکسشو میدم بگو این تو چه بیماریه!'><br> | |
| <input type="file" id="imageFileInput" accept="image/*"><br> | |
| ` | |
| } | |
| function add3() { | |
| document.getElementById('div-3').innerHTML=document.getElementById('div-3').innerHTML + ` | |
| <input type="text" name="" value="" placeholder='پاپول هایپرکراتوز چرب در نواحی سبورئیک به همراه ناهنجاری ناخن ها و تعداد زیادی پاپول کوچک در سقف دهان'><br> | |
| <input type="file" id="imageFileInput" accept="image/*"><br> | |
| ` | |
| } | |
| function add4() { | |
| document.getElementById('div-4').innerHTML=document.getElementById('div-4').innerHTML + ` | |
| <input type="text" name="" value="" placeholder='مثال : U/A, CBC, LFT...'><br> | |
| <input type="file" id="imageFileInput" accept="image/*"><br> | |
| ` | |
| } | |
| function add5() { | |
| document.getElementById('div-5').innerHTML=document.getElementById('div-5').innerHTML + ` | |
| <input type="text" name="" value="" placeholder='اکسیژن بافت پانکراس در آقای 72 ساله با شکایت زردی و کاهش وزن'><br> | |
| <input type="file" id="imageFileInput" accept="image/*"><br> | |
| ` | |
| } | |
| </script> | |
| <script type="importmap"> | |
| { | |
| "imports": { | |
| "@google/generative-ai": "https://esm.run/@google/generative-ai" | |
| } | |
| } | |
| </script> | |
| <script type="module"> | |
| import { GoogleGenerativeAI } from "@google/generative-ai"; | |
| // Access your API key (make sure this is secure and not exposed) | |
| const genAI = new GoogleGenerativeAI("AIzaSyBd36RWeqDpLur3E7TTlX3wnyIh_rdhsU8"); | |
| // Converts a File object to a GoogleGenerativeAI.Part object. | |
| async function fileToGenerativePart(file) { | |
| const base64EncodedDataPromise = new Promise((resolve, reject) => { | |
| const reader = new FileReader(); | |
| reader.onloadend = () => resolve(reader.result.split(',')[1]); | |
| reader.onerror = reject; | |
| reader.readAsDataURL(file); | |
| }); | |
| return { | |
| inlineData: { data: await base64EncodedDataPromise, mimeType: file.type }, | |
| }; | |
| } | |
| async function run() { | |
| // For text-and-images input (multimodal), use the gemini-pro-vision model | |
| const model = genAI.getGenerativeModel({ model: "gemini-pro-vision" }); | |
| const prompt = "What's this?"; | |
| const fileInputEl = document.getElementById("imageFileInput"); | |
| // Check if the user has selected an image | |
| if (fileInputEl.files.length === 0) { | |
| alert("Please select an image."); | |
| return; | |
| } | |
| try { | |
| const imageParts = await Promise.all( | |
| [...fileInputEl.files].map(fileToGenerativePart) | |
| ); | |
| // Generate content using the image and the prompt | |
| const result = await model.generateContent([prompt, ...imageParts]); | |
| const response = await result.response; | |
| const text = await response.text(); | |
| // Update your DOM or take action with the response text here | |
| // For example, show the result in the 'n' input element | |
| document.getElementById('n').value = text; | |
| } catch (error) { | |
| console.error('Error during generation:', error); | |
| // Handle the error e.g., show error message to user | |
| } | |
| } | |
| document.getElementById('calculateButton').addEventListener('click', run); | |
| // Removed unused code from the previous version | |
| </script> | |
| """ | |
| # Combining HTML, CSS, and JavaScript | |
| combined_content = css_content + html_content + js_code | |
| # Render the combined HTML/CSS/JavaScript with a specified height | |
| components.html(combined_content, height=1700, width=100%) | |
| # Streamlit equivalent components | |
| st.header("Hello, Streamlit!") | |
| st.write("This is a paragraph in a custom style.") | |
| if st.button("Click Me"): | |
| st.write("Button Clicked!") |