CoolFace
Apppublic

AGayathriiii/DotNetJavaCodeConversion

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
codegen2.py30 linesDownload Raw Back to backend
1import streamlit as st2from huggingface_hub import InferenceClient3 4HF_TOKEN = st.secrets["HF_API_KEY"]5 6def convert_with_codegen2(code):7    prompt = f"Convert the following C# code to Java:\n\n{code}\n\nJava Code:"8 9    try:10        client = InferenceClient("bigcode/starcoder", token=HF_TOKEN)11        response = client.text_generation(prompt, max_new_tokens=512, temperature=0.3, top_p=0.95)12        return response.strip()13    except Exception as e1:14        print("❌ StarCoder failed:", e1)15 16    try:17        client = InferenceClient("deepseek-ai/deepseek-coder-1.3b-instruct", token=HF_TOKEN)18        response = client.text_generation(prompt, max_new_tokens=512, temperature=0.3, top_p=0.95)19        return "[⚠️ Using fallback: DeepSeek-Coder]\n" + response.strip()20    except Exception as e2:21        print("❌ DeepSeek-Coder failed:", e2)22 23    try:24        client = InferenceClient("Salesforce/codegen2-1B", token=HF_TOKEN)25        response = client.text_generation(prompt, max_new_tokens=512, temperature=0.3, top_p=0.95)26        return "[⚠️ Using fallback: CodeGen2-1B]\n" + response.strip()27    except Exception as e3:28        print("❌ CodeGen2-1B failed:", e3)29 30    return "💥 All model servers are currently unavailable. Please try again later!"