-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
38 lines (33 loc) · 1.41 KB
/
app.py
File metadata and controls
38 lines (33 loc) · 1.41 KB
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
import streamlit as st
import os
from converter import convert_python_to_java
st.set_page_config(page_title="LLM Code Migrator", page_icon="🚀")
st.title("🚀 AI Code Migration Tool")
st.write("Convert Python code into Java using Claude AI")
# API Key input in sidebar
with st.sidebar:
api_key = st.text_input("Anthropic API Key", type="password", placeholder="sk-ant-...")
if api_key:
os.environ["ANTHROPIC_API_KEY"] = api_key
st.success("API key set!")
else:
st.warning("Enter your Anthropic API key to use the converter")
python_code = st.text_area("Enter Python Code", height=300, placeholder="print('Hello World!')")
if st.button("Convert to Java"):
if not os.environ.get("ANTHROPIC_API_KEY"):
st.error("Please enter your Anthropic API key in the sidebar first.")
elif python_code.strip() == "":
st.warning("Please enter some Python code")
else:
with st.spinner("Converting using Claude AI..."):
try:
java_code = convert_python_to_java(python_code)
st.subheader("Generated Java Code")
st.code(java_code, language="java")
st.download_button(
label="Download Java File",
data=java_code,
file_name="ConvertedCode.java",
)
except Exception as e:
st.error(f"Conversion failed: {e}")