import gradio as gr from deep_translator import GoogleTranslator # Function to handle translation logic def translate_to_us(text_input): if not text_input or not text_input.strip(): return "" try: # Auto-detect source language and translate to English (US) return GoogleTranslator(source='auto', target='en').translate(text_input) except Exception as e: return f"Error: {str(e)}" # Function to show/hide the translation box def toggle_translator(current_visibility): return gr.update(visible=not current_visibility), not current_visibility # Correct Iframe URL for Hugging Face Spaces # Using the direct .hf.space link to avoid X-Frame-Options block source_space_url = "https://svngoku-firered-image-edit-1-0-fast.hf.space" with gr.Blocks(fill_height=True, title="FireRed Direct Iframe") as demo: # 1. Main Interface (Iframe) gr.HTML(f""" """) # State to keep track of visibility is_visible = gr.State(False) # 2. Small Toggle Button at the bottom with gr.Row(): gr.Markdown("---") show_btn = gr.Button("🌐 Open Translation Helper", variant="secondary", size="sm") # 3. Hidden Translation Section with gr.Column(visible=False) as translation_box: with gr.Row(): input_box = gr.Textbox( label="Input (Auto-detect)", placeholder="Type your prompt here...", lines=2 ) output_box = gr.Textbox( label="English (US) Result", interactive=True, show_copy_button=True ) run_btn = gr.Button("Translate Now", variant="primary") # Link translation button run_btn.click( fn=translate_to_us, inputs=input_box, outputs=output_box ) # Toggle logic for the show/hide button show_btn.click( fn=toggle_translator, inputs=is_visible, outputs=[translation_box, is_visible] ) if __name__ == "__main__": demo.launch()