Spaces:
Sleeping
Sleeping
Download src/streamlit_app.py from Ait-Achour/PseudoCodeRAG-Translator: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/Ait-Achour/PseudoCodeRAG-Translator/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/Ait-Achour/PseudoCodeRAG-Translator/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/Ait-Achour/PseudoCodeRAG-Translator/resolve/main/src/streamlit_app.py
1.03 kB
| import streamlit as st | |
| from google import genai | |
| import os | |
| st.set_page_config(page_title="Python → Java Translator", layout="wide") | |
| st.title("Python → Java Translator (Gemini 3 Flash)") | |
| API_KEY = os.environ.get("GEMINI_API_KEY") | |
| if not API_KEY: | |
| st.error("GEMINI_API_KEY not found. Add it in Settings → Secrets.") | |
| st.stop() | |
| client = genai.Client(api_key=API_KEY) | |
| python_code = st.text_area("Enter Python Code", height=250) | |
| if st.button("Translate"): | |
| if not python_code.strip(): | |
| st.warning("Please enter Python code.") | |
| else: | |
| prompt = f""" | |
| You are an expert software engineer. | |
| Translate the following Python code into clean, modern Java. | |
| Only output the Java code. | |
| Python Code: | |
| {python_code} | |
| Java Code: | |
| """ | |
| with st.spinner("Generating..."): | |
| response = client.models.generate_content( | |
| model="gemini-3-flash-preview", | |
| contents=prompt, | |
| ) | |
| st.subheader("Generated Java Code") | |
| st.code(response.text, language="java") |