Spaces:
Running
Running
Update app.py
Browse files12345615 unmodified lines2223242526272818 unmodified lines47484950515220 unmodified lines737475767778798081828384858687888990911 unmodified line939495969798991001011021031041051061071081091101111121131141151161178 unmodified lines1261271281291301319 unmodified lines1411421431441451461471481491501511521531541551561571581591601611621631643 unmodified lines16816917017117217317417517617717829 unmodified lines2082092102112122132144 unmodified lines2192202212222232242252262272282296 unmodified lines2362372382392402412422432442452462472482492502512522532542552562572582594 unmodified lines26426526626726826927027127227327427527627727827928028128228328428528628713 unmodified lines30130230330430530630735 unmodified lines3433443453463473483497 unmodified lines35735835936036136236323 unmodified lines38738838939039139239323 unmodified lines4174184194204214224234244254264271 unmodified line429430431432433434435436437438"""DNA-Diffusion Gradio ApplicationInteractive DNA sequence generation with slot machine visualization and protein analysis"""import gradio as gr15 unmodified linesSPACES_AVAILABLE = Trueexcept ImportError:SPACES_AVAILABLE = False# Create a dummy decorator if spaces is not availableclass spaces:@staticmethoddef GPU(duration=60):18 unmodified lineswith open(HTML_FILE, "r") as f:SLOT_MACHINE_HTML = f.read()class ProteinAnalyzer:"""Handles protein translation and analysis using LLM"""20 unmodified lines@staticmethoddef dna_to_protein(dna_sequence: str) -> str:"""Translate DNA sequence to protein sequence"""# Ensure sequence is uppercasedna_sequence = dna_sequence.upper()# Remove any non-DNA charactersdna_sequence = ''.join(c for c in dna_sequence if c in 'ATCG')# Translate to proteinprotein = []for i in range(0, len(dna_sequence) - 2, 3):codon = dna_sequence[i:i+3]if len(codon) == 3:amino_acid = ProteinAnalyzer.CODON_TABLE.get(codon, 'X')if amino_acid == '*': # Stop codonbreakprotein.append(amino_acid)1 unmodified line@staticmethoddef analyze_protein_with_llm(protein_sequence: str, cell_type: str, language: str = "en") -> str:"""Analyze protein structure and function using Friendli LLM API"""# Get API token from environmenttoken = os.getenv("FRIENDLI_TOKEN")if not token:logger.warning("FRIENDLI_TOKEN not found in environment variables")if language == "ko":return "๋จ๋ฐฑ์ง ๋ถ์ ๋ถ๊ฐ: API ํ ํฐ์ด ์ค์ ๋์ง ์์์ต๋๋ค"return "Protein analysis unavailable: API token not configured"try:url = "https://api.friendli.ai/dedicated/v1/chat/completions"headers = {"Authorization": f"Bearer {token}","Content-Type": "application/json"}# Create prompt for protein analysis based on languageif language == "ko":prompt = f"""๋น์ ์ ์๋ฌผ์ ๋ณดํ ์ ๋ฌธ๊ฐ์ ๋๋ค. ๋ค์ ๋จ๋ฐฑ์ง ์์ด์ ๋ถ์ํ๊ณ ์ ์ฌ์ ์ธ ๊ตฌ์กฐ์ ๊ธฐ๋ฅ์ ๋ํ ํต์ฐฐ๋ ฅ์ ์ ๊ณตํด์ฃผ์ธ์.๋จ๋ฐฑ์ง ์์ด: {protein_sequence}8 unmodified lines๊ณผํ ์ ํ๋ฆฌ์ผ์ด์ ์ ํ์ํ๊ธฐ์ ์ ํฉํ๋๋ก ๊ฐ๊ฒฐํ๋ฉด์๋ ์ ์ตํ ์๋ต์ ์์ฑํด์ฃผ์ธ์."""else:prompt = f"""You are a bioinformatics expert. Analyze the following protein sequence and provide insights about its potential structure and function.Protein sequence: {protein_sequence}9 unmodified linesKeep the response concise but informative, suitable for display in a scientific application."""payload = {"model": "dep86pjolcjjnv8","messages": [{"role": "system","content": "You are a knowledgeable bioinformatics assistant specializing in protein structure and function prediction." if language == "en" else "๋น์ ์ ๋จ๋ฐฑ์ง ๊ตฌ์กฐ์ ๊ธฐ๋ฅ ์์ธก์ ์ ๋ฌธ์ผ๋ก ํ๋ ์ง์์ด ํ๋ถํ ์๋ฌผ์ ๋ณดํ ์ด์์คํดํธ์ ๋๋ค."},{"role": "user","content": prompt}],"max_tokens": 1000,"temperature": 0.7,"top_p": 0.8,"stream": False # Disable streaming for simplicity}response = requests.post(url, json=payload, headers=headers, timeout=30)response.raise_for_status()result = response.json()3 unmodified linesexcept requests.exceptions.RequestException as e:logger.error(f"Failed to analyze protein with LLM: {e}")return f"Protein analysis failed: {str(e)}"except Exception as e:logger.error(f"Unexpected error during protein analysis: {e}")return "Protein analysis unavailable due to an error"class DNADiffusionApp:"""Main application class for DNA-Diffusion Gradio interface"""29 unmodified linesdef generate_sequence(self, cell_type: str, guidance_scale: float = 1.0) -> Tuple[str, Dict[str, Any]]:"""Generate a DNA sequence using the model or mock data"""# Use mock generation if model is not availableif not MODEL_AVAILABLE or self.model is None:logger.warning("Using mock sequence generation")import random4 unmodified lines'generation_time': 2.0,'mock': True}# Simulate generation timetime.sleep(2.0)return sequence, metadata# Use real modeltry:result = self.model.generate(cell_type, guidance_scale)return result['sequence'], result['metadata']6 unmodified linestry:logger.info(f"Generating sequence for cell type: {cell_type}, language: {language}")# Generate DNA sequencesequence, metadata = self.generate_sequence(cell_type, guidance_scale)# Translate to proteinlogger.info("Translating DNA to protein sequence...")protein_sequence = self.protein_analyzer.dna_to_protein(sequence)# Add protein sequence to metadatametadata['protein_sequence'] = protein_sequencemetadata['protein_length'] = len(protein_sequence)# Analyze protein with LLMlogger.info("Analyzing protein structure and function...")protein_analysis = self.protein_analyzer.analyze_protein_with_llm(protein_sequence, cell_type, language)# Add analysis to metadatametadata['protein_analysis'] = protein_analysislogger.info("Generation and analysis complete")4 unmodified lineslogger.error(f"Generation request failed: {error_msg}")return "", json.dumps({"error": error_msg})# Create single app instanceapp = DNADiffusionApp()def create_demo():"""Create the Gradio demo interface"""# CSS to hide backend controls and prevent scrollingcss = """#hidden-controls { display: none !important; }.gradio-container {overflow: hidden;background-color: #000000 !important;}#dna-frame { overflow: hidden; position: relative; }body {background-color: #000000 !important;}"""# JavaScript for handling communication between iframe and Gradiojs = """13 unmodified linesradioInputs.forEach(input => {if (input.value === event.data.cellType) {input.checked = true;// Trigger change eventinput.dispatchEvent(new Event('change'));}});35 unmodified lines}} catch (e) {console.error('Failed to parse metadata:', e);// If parsing fails, still send the sequenceiframe.contentWindow.postMessage({type: 'sequence_generated',sequence: sequence,7 unmodified lines}"""with gr.Blocks(css=css, js=js, theme=gr.themes.Base()) as demo:# Hidden controls for backend processingwith gr.Column(elem_id="hidden-controls", visible=False):23 unmodified linesmetadata_output = gr.Textbox(label="Metadata", elem_id="metadata-output")# Main interface - the slot machine in an iframe# Escape the HTML content for srcdocescaped_html = html.escape(SLOT_MACHINE_HTML, quote=True)iframe_html = f'<iframe srcdoc="{escaped_html}" style="width: 100%; height: 800px; border: none; display: block;"></iframe>'23 unmodified linesreturn demo# Launch the appif __name__ == "__main__":demo = create_demo()# Parse any command line argumentsimport argparseparser = argparse.ArgumentParser(description="DNA-Diffusion Gradio App")parser.add_argument("--share", action="store_true", help="Create a public shareable link")1 unmodified lineparser.add_argument("--host", type=str, default="0.0.0.0", help="Host to run the app on")args = parser.parse_args()# For Hugging Face Spaces deploymentimport osif os.getenv("SPACE_ID"):# Running on Hugging Face Spacesargs.host = "0.0.0.0"args.port = 7860args.share = False123456715 unmodified lines23242526272818 unmodified lines4748495051525320 unmodified lines7475767778798081828384858687881 unmodified line909192939495969798991001011021031041051061071081091101118 unmodified lines1201211221231241251269 unmodified lines1361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661673 unmodified lines17117217317417517617717817918018118218318418518629 unmodified lines2162172182192202214 unmodified lines2262272282292302312322332346 unmodified lines2412422432442452462472482492502512522532542552562572582594 unmodified lines26426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460513 unmodified lines61962062162262362435 unmodified lines6606616626636646657 unmodified lines67367467567667767867968068168268368468568668768868969069169269369469569669769869970070170223 unmodified lines72672772872973073123 unmodified lines7557567577587597607617627637647651 unmodified line767768769770771772773"""DNA-Diffusion Gradio ApplicationInteractive DNA sequence generation with slot machine visualization and protein analysisComic Classic Theme Applied"""import gradio as gr15 unmodified linesSPACES_AVAILABLE = Trueexcept ImportError:SPACES_AVAILABLE = Falseclass spaces:@staticmethoddef GPU(duration=60):18 unmodified lineswith open(HTML_FILE, "r") as f:SLOT_MACHINE_HTML = f.read()class ProteinAnalyzer:"""Handles protein translation and analysis using LLM"""20 unmodified lines@staticmethoddef dna_to_protein(dna_sequence: str) -> str:"""Translate DNA sequence to protein sequence"""dna_sequence = dna_sequence.upper()dna_sequence = ''.join(c for c in dna_sequence if c in 'ATCG')protein = []for i in range(0, len(dna_sequence) - 2, 3):codon = dna_sequence[i:i+3]if len(codon) == 3:amino_acid = ProteinAnalyzer.CODON_TABLE.get(codon, 'X')if amino_acid == '*':breakprotein.append(amino_acid)1 unmodified line@staticmethoddef analyze_protein_with_llm(protein_sequence: str, cell_type: str, language: str = "en") -> str:"""Analyze protein structure and function using Fireworks AI LLM API"""# Get API token from environmentapi_key = os.getenv("FIREWORKS_API_KEY")if not api_key:logger.warning("FIREWORKS_API_KEY not found in environment variables")if language == "ko":return "๋จ๋ฐฑ์ง ๋ถ์ ๋ถ๊ฐ: API ํ ํฐ์ด ์ค์ ๋์ง ์์์ต๋๋ค"return "Protein analysis unavailable: API token not configured"try:url = "https://api.fireworks.ai/inference/v1/chat/completions"# Create prompt for protein analysis based on languageif language == "ko":system_content = "๋น์ ์ ๋จ๋ฐฑ์ง ๊ตฌ์กฐ์ ๊ธฐ๋ฅ ์์ธก์ ์ ๋ฌธ์ผ๋ก ํ๋ ์ง์์ด ํ๋ถํ ์๋ฌผ์ ๋ณดํ ์ด์์คํดํธ์ ๋๋ค."prompt = f"""๋น์ ์ ์๋ฌผ์ ๋ณดํ ์ ๋ฌธ๊ฐ์ ๋๋ค. ๋ค์ ๋จ๋ฐฑ์ง ์์ด์ ๋ถ์ํ๊ณ ์ ์ฌ์ ์ธ ๊ตฌ์กฐ์ ๊ธฐ๋ฅ์ ๋ํ ํต์ฐฐ๋ ฅ์ ์ ๊ณตํด์ฃผ์ธ์.๋จ๋ฐฑ์ง ์์ด: {protein_sequence}8 unmodified lines๊ณผํ ์ ํ๋ฆฌ์ผ์ด์ ์ ํ์ํ๊ธฐ์ ์ ํฉํ๋๋ก ๊ฐ๊ฒฐํ๋ฉด์๋ ์ ์ตํ ์๋ต์ ์์ฑํด์ฃผ์ธ์."""else:system_content = "You are a knowledgeable bioinformatics assistant specializing in protein structure and function prediction."prompt = f"""You are a bioinformatics expert. Analyze the following protein sequence and provide insights about its potential structure and function.Protein sequence: {protein_sequence}9 unmodified linesKeep the response concise but informative, suitable for display in a scientific application."""payload = {"model": "accounts/fireworks/models/gpt-oss-120b","max_tokens": 4096,"top_p": 1,"top_k": 40,"presence_penalty": 0,"frequency_penalty": 0,"temperature": 0.6,"messages": [{"role": "system","content": system_content},{"role": "user","content": prompt}]}headers = {"Accept": "application/json","Content-Type": "application/json","Authorization": f"Bearer {api_key}"}response = requests.post(url, headers=headers, data=json.dumps(payload), timeout=60)response.raise_for_status()result = response.json()3 unmodified linesexcept requests.exceptions.RequestException as e:logger.error(f"Failed to analyze protein with LLM: {e}")if language == "ko":return f"๋จ๋ฐฑ์ง ๋ถ์ ์คํจ: {str(e)}"return f"Protein analysis failed: {str(e)}"except Exception as e:logger.error(f"Unexpected error during protein analysis: {e}")if language == "ko":return "์ค๋ฅ๋ก ์ธํด ๋จ๋ฐฑ์ง ๋ถ์์ ์ฌ์ฉํ ์ ์์ต๋๋ค"return "Protein analysis unavailable due to an error"class DNADiffusionApp:"""Main application class for DNA-Diffusion Gradio interface"""29 unmodified linesdef generate_sequence(self, cell_type: str, guidance_scale: float = 1.0) -> Tuple[str, Dict[str, Any]]:"""Generate a DNA sequence using the model or mock data"""if not MODEL_AVAILABLE or self.model is None:logger.warning("Using mock sequence generation")import random4 unmodified lines'generation_time': 2.0,'mock': True}time.sleep(2.0)return sequence, metadatatry:result = self.model.generate(cell_type, guidance_scale)return result['sequence'], result['metadata']6 unmodified linestry:logger.info(f"Generating sequence for cell type: {cell_type}, language: {language}")sequence, metadata = self.generate_sequence(cell_type, guidance_scale)logger.info("Translating DNA to protein sequence...")protein_sequence = self.protein_analyzer.dna_to_protein(sequence)metadata['protein_sequence'] = protein_sequencemetadata['protein_length'] = len(protein_sequence)logger.info("Analyzing protein structure and function...")protein_analysis = self.protein_analyzer.analyze_protein_with_llm(protein_sequence, cell_type, language)metadata['protein_analysis'] = protein_analysislogger.info("Generation and analysis complete")4 unmodified lineslogger.error(f"Generation request failed: {error_msg}")return "", json.dumps({"error": error_msg})# Create single app instanceapp = DNADiffusionApp()# ============================================# ๐จ Comic Classic Theme - Toon Playground# ============================================css = """/* ===== ๐จ Google Fonts Import ===== */@import url('https://fonts.googleapis.com/css2?family=Bangers&family=Comic+Neue:wght@400;700&display=swap');/* ===== ๐จ Comic Classic ๋ฐฐ๊ฒฝ - ๋นํฐ์ง ํ์ดํผ + ๋ํธ ํจํด ===== */.gradio-container {background-color: #FEF9C3 !important;background-image:radial-gradient(#1F2937 1px, transparent 1px) !important;background-size: 20px 20px !important;min-height: 100vh !important;font-family: 'Comic Neue', cursive, sans-serif !important;}/* ===== ํ๊น ํ์ด์ค ์๋จ ์์ ์จ๊น ===== */.huggingface-space-header,#space-header,.space-header,[class*="space-header"],.svelte-1ed2p3z,.space-header-badge,.header-badge,[data-testid="space-header"],.svelte-kqij2n,.svelte-1ax1toq,.embed-container > div:first-child {display: none !important;visibility: hidden !important;height: 0 !important;width: 0 !important;overflow: hidden !important;opacity: 0 !important;pointer-events: none !important;}/* ===== Footer ์์ ์จ๊น ===== */footer,.footer,.gradio-container footer,.built-with,[class*="footer"],.gradio-footer,.main-footer,div[class*="footer"],.show-api,.built-with-gradio,a[href*="gradio.app"],a[href*="huggingface.co/spaces"] {display: none !important;visibility: hidden !important;height: 0 !important;padding: 0 !important;margin: 0 !important;}/* ===== Hidden controls ์จ๊น ===== */#hidden-controls {display: none !important;}/* ===== ๋ฉ์ธ ์ปจํ ์ด๋ ===== */#col-container {max-width: 1200px;margin: 0 auto;}/* ===== ๐จ ํค๋ ํ์ดํ - ์ฝ๋ฏน ์คํ์ผ ===== */.header-text h1 {font-family: 'Bangers', cursive !important;color: #1F2937 !important;font-size: 3.5rem !important;font-weight: 400 !important;text-align: center !important;margin-bottom: 0.5rem !important;text-shadow:4px 4px 0px #FACC15,6px 6px 0px #1F2937 !important;letter-spacing: 3px !important;-webkit-text-stroke: 2px #1F2937 !important;}/* ===== ๐จ ์๋ธํ์ดํ ===== */.subtitle {text-align: center !important;font-family: 'Comic Neue', cursive !important;font-size: 1.2rem !important;color: #1F2937 !important;margin-bottom: 1.5rem !important;font-weight: 700 !important;}/* ===== ๐จ ์นด๋/ํจ๋ - ๋งํ ํ๋ ์ ์คํ์ผ ===== */.gr-panel,.gr-box,.gr-form,.block,.gr-group {background: #FFFFFF !important;border: 3px solid #1F2937 !important;border-radius: 8px !important;box-shadow: 6px 6px 0px #1F2937 !important;transition: all 0.2s ease !important;}.gr-panel:hover,.block:hover {transform: translate(-2px, -2px) !important;box-shadow: 8px 8px 0px #1F2937 !important;}/* ===== ๐จ ์ ๋ ฅ ํ๋ (Textbox) ===== */textarea,input[type="text"],input[type="number"] {background: #FFFFFF !important;border: 3px solid #1F2937 !important;border-radius: 8px !important;color: #1F2937 !important;font-family: 'Comic Neue', cursive !important;font-size: 1rem !important;font-weight: 700 !important;transition: all 0.2s ease !important;}textarea:focus,input[type="text"]:focus,input[type="number"]:focus {border-color: #3B82F6 !important;box-shadow: 4px 4px 0px #3B82F6 !important;outline: none !important;}/* ===== ๐จ ๋ผ๋์ค ๋ฒํผ ์คํ์ผ ===== */.gr-radio {background: #FFFFFF !important;border: 3px solid #1F2937 !important;border-radius: 8px !important;box-shadow: 4px 4px 0px #1F2937 !important;padding: 10px !important;}.gr-radio label {font-family: 'Comic Neue', cursive !important;font-weight: 700 !important;color: #1F2937 !important;}.gr-radio input[type="radio"]:checked + label {color: #3B82F6 !important;}/* ===== ๐จ Primary ๋ฒํผ - ์ฝ๋ฏน ๋ธ๋ฃจ ===== */.gr-button-primary,button.primary,.gr-button.primary,.generate-btn {background: #3B82F6 !important;border: 3px solid #1F2937 !important;border-radius: 8px !important;color: #FFFFFF !important;font-family: 'Bangers', cursive !important;font-weight: 400 !important;font-size: 1.3rem !important;letter-spacing: 2px !important;padding: 14px 28px !important;box-shadow: 5px 5px 0px #1F2937 !important;transition: all 0.1s ease !important;text-shadow: 1px 1px 0px #1F2937 !important;}.gr-button-primary:hover,button.primary:hover,.gr-button.primary:hover,.generate-btn:hover {background: #2563EB !important;transform: translate(-2px, -2px) !important;box-shadow: 7px 7px 0px #1F2937 !important;}.gr-button-primary:active,button.primary:active,.gr-button.primary:active,.generate-btn:active {transform: translate(3px, 3px) !important;box-shadow: 2px 2px 0px #1F2937 !important;}/* ===== ๐จ Secondary ๋ฒํผ - ์ฝ๋ฏน ๋ ๋ ===== */.gr-button-secondary,button.secondary {background: #EF4444 !important;border: 3px solid #1F2937 !important;border-radius: 8px !important;color: #FFFFFF !important;font-family: 'Bangers', cursive !important;font-weight: 400 !important;font-size: 1.1rem !important;letter-spacing: 1px !important;box-shadow: 4px 4px 0px #1F2937 !important;transition: all 0.1s ease !important;text-shadow: 1px 1px 0px #1F2937 !important;}.gr-button-secondary:hover,button.secondary:hover {background: #DC2626 !important;transform: translate(-2px, -2px) !important;box-shadow: 6px 6px 0px #1F2937 !important;}/* ===== ๐จ ์ฌ๋ผ์ด๋ ์คํ์ผ ===== */input[type="range"] {accent-color: #3B82F6 !important;}.gr-slider {background: #FFFFFF !important;}/* ===== ๐จ ๋ผ๋ฒจ ์คํ์ผ ===== */label,.gr-input-label,.gr-block-label {color: #1F2937 !important;font-family: 'Comic Neue', cursive !important;font-weight: 700 !important;font-size: 1rem !important;}span.gr-label {color: #1F2937 !important;}/* ===== ๐จ DNA Slot Machine iframe ํ๋ ์ ===== */#dna-frame {overflow: hidden;position: relative;border: 4px solid #1F2937 !important;border-radius: 12px !important;box-shadow: 8px 8px 0px #1F2937 !important;background: #000000 !important;}#dna-frame iframe {border: none !important;display: block !important;}/* ===== ๐จ ์คํฌ๋กค๋ฐ - ์ฝ๋ฏน ์คํ์ผ ===== */::-webkit-scrollbar {width: 12px;height: 12px;}::-webkit-scrollbar-track {background: #FEF9C3;border: 2px solid #1F2937;}::-webkit-scrollbar-thumb {background: #3B82F6;border: 2px solid #1F2937;border-radius: 0px;}::-webkit-scrollbar-thumb:hover {background: #EF4444;}/* ===== ๐จ ์ ํ ํ์ด๋ผ์ดํธ ===== */::selection {background: #FACC15;color: #1F2937;}/* ===== ๐จ ๋งํฌ ์คํ์ผ ===== */a {color: #3B82F6 !important;text-decoration: none !important;font-weight: 700 !important;}a:hover {color: #EF4444 !important;}/* ===== ๐จ Row/Column ๊ฐ๊ฒฉ ===== */.gr-row {gap: 1.5rem !important;}.gr-column {gap: 1rem !important;}/* ===== ๋ฐ์ํ ์กฐ์ ===== */@media (max-width: 768px) {.header-text h1 {font-size: 2.2rem !important;text-shadow:3px 3px 0px #FACC15,4px 4px 0px #1F2937 !important;}.gr-button-primary,button.primary {padding: 12px 20px !important;font-size: 1.1rem !important;}.gr-panel,.block {box-shadow: 4px 4px 0px #1F2937 !important;}}/* ===== ๐จ ๋คํฌ๋ชจ๋ ๋นํ์ฑํ ===== */@media (prefers-color-scheme: dark) {.gradio-container {background-color: #FEF9C3 !important;}}"""def create_demo():"""Create the Gradio demo interface"""# JavaScript for handling communication between iframe and Gradiojs = """13 unmodified linesradioInputs.forEach(input => {if (input.value === event.data.cellType) {input.checked = true;input.dispatchEvent(new Event('change'));}});35 unmodified lines}} catch (e) {console.error('Failed to parse metadata:', e);iframe.contentWindow.postMessage({type: 'sequence_generated',sequence: sequence,7 unmodified lines}"""with gr.Blocks(css=css, js=js, fill_height=True) as demo:# HOME Badgegr.HTML("""<div style="text-align: center; margin: 20px 0 10px 0;"><a href="https://www.humangen.ai" target="_blank" style="text-decoration: none;"><img src="https://img.shields.io/static/v1?label=๐ HOME&message=HUMANGEN.AI&color=0000ff&labelColor=ffcc00&style=for-the-badge" alt="HOME"></a></div>""")# Header Titlegr.Markdown("""# ๐งฌ DNA DIFFUSION GENERATOR ๐ฐ""",elem_classes="header-text")gr.Markdown("""<p class="subtitle">๐ฌ Generate DNA sequences with AI-powered diffusion model! Translate to protein & analyze! ๐งช</p>""",)# Hidden controls for backend processingwith gr.Column(elem_id="hidden-controls", visible=False):23 unmodified linesmetadata_output = gr.Textbox(label="Metadata", elem_id="metadata-output")# Main interface - the slot machine in an iframeescaped_html = html.escape(SLOT_MACHINE_HTML, quote=True)iframe_html = f'<iframe srcdoc="{escaped_html}" style="width: 100%; height: 800px; border: none; display: block;"></iframe>'23 unmodified linesreturn demo# Launch the appif __name__ == "__main__":demo = create_demo()import argparseparser = argparse.ArgumentParser(description="DNA-Diffusion Gradio App")parser.add_argument("--share", action="store_true", help="Create a public shareable link")1 unmodified lineparser.add_argument("--host", type=str, default="0.0.0.0", help="Host to run the app on")args = parser.parse_args()if os.getenv("SPACE_ID"):args.host = "0.0.0.0"args.port = 7860args.share = False
app.py+386-51