File size: 1,034 Bytes
67b27bd
5186b39
22980d2
67b27bd
ec73d86
5186b39
ec73d86
22980d2
ec73d86
22980d2
 
 
a4e069e
5186b39
ec73d86
 
 
 
 
 
 
 
22980d2
ec73d86
28bf44c
ec73d86
22980d2
ec73d86
 
22980d2
67b27bd
 
22980d2
5186b39
 
 
 
28bf44c
 
5d3eba5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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")