|
|
import streamlit as st |
|
|
from langchain.chat_models import ChatOpenAI |
|
|
from langchain_groq import ChatGroq |
|
|
|
|
|
|
|
|
|
|
|
st.title("JavaScript to Perl Converter") |
|
|
groq_api_key = "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" |
|
|
llm = ChatGroq(groq_api_key=groq_api_key, model_name="llama-3.1-70b-versatile") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.subheader("Input JavaScript Code") |
|
|
javascript_code = st.text_area("Paste your JavaScript code below:", height=600) |
|
|
|
|
|
convert_button = st.button("Convert to Perl") |
|
|
|
|
|
|
|
|
def convert_to_perl(js_code): |
|
|
prompt = ( |
|
|
f"Convert the following JavaScript code to an equivalent Perl program. Ensure all logic is preserved, " |
|
|
f"and Perl best practices are followed. Provide the output in Perl format only, without additional text.\n\n" |
|
|
f"JavaScript Code:\n{js_code}" |
|
|
) |
|
|
if llm: |
|
|
response = llm.predict(prompt) |
|
|
return response |
|
|
else: |
|
|
return "Please configure the API key in the sidebar." |
|
|
|
|
|
|
|
|
if convert_button: |
|
|
if not javascript_code.strip(): |
|
|
st.warning("Please enter some JavaScript code to convert.") |
|
|
elif not llm: |
|
|
st.warning("API key is required to perform the conversion.") |
|
|
else: |
|
|
st.subheader("Converted Perl Code") |
|
|
perl_code = convert_to_perl(javascript_code) |
|
|
st.text_area("Output Perl Code", perl_code, height=600) |
|
|
|
|
|
|
|
|
st.download_button( |
|
|
label="Download Perl Code", |
|
|
data=perl_code, |
|
|
file_name="converted_code.pl", |
|
|
mime="text/plain" |
|
|
) |
|
|
|