Krish-Upgrix commited on
Commit
c41fc21
·
verified ·
1 Parent(s): 8095df0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -5,7 +5,7 @@ import google.generativeai as genai # Import Gemini API
5
 
6
  # Load API keys from environment variables
7
  HF_API_TOKEN = os.getenv("HF_API_TOKEN")
8
- GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
9
 
10
  # Set up Hugging Face API
11
  MODEL_ID = "Salesforce/codet5p-770m" # CodeT5+ (Recommended)
@@ -13,7 +13,7 @@ API_URL = f"https://api-inference.huggingface.co/models/{MODEL_ID}"
13
  HEADERS = {"Authorization": f"Bearer {HF_API_TOKEN}"}
14
 
15
  # Initialize Gemini API
16
- genai.configure(api_key=GEMINI_API_KEY)
17
 
18
  def translate_code(code_snippet, source_lang, target_lang):
19
  """Translate code using Hugging Face API."""
@@ -42,9 +42,10 @@ def fallback_translate_with_gemini(code_snippet, source_lang, target_lang):
42
  {code_snippet}
43
 
44
  Ensure the translation is accurate and follows {target_lang} best practices.
 
45
  """
46
  try:
47
- model = genai.GenerativeModel("gemini-pro")
48
  response = model.generate_content(prompt)
49
  return response.text.strip() if response else "Translation failed."
50
  except Exception as e:
 
5
 
6
  # Load API keys from environment variables
7
  HF_API_TOKEN = os.getenv("HF_API_TOKEN")
8
+ GEMINI_API_KEY = os.getenv("GOOGLE_API_KEY")
9
 
10
  # Set up Hugging Face API
11
  MODEL_ID = "Salesforce/codet5p-770m" # CodeT5+ (Recommended)
 
13
  HEADERS = {"Authorization": f"Bearer {HF_API_TOKEN}"}
14
 
15
  # Initialize Gemini API
16
+ genai.configure(api_key='AIzaSyBkc8CSEhyYwZAuUiJfzF1Xtns-RYmBOpg')
17
 
18
  def translate_code(code_snippet, source_lang, target_lang):
19
  """Translate code using Hugging Face API."""
 
42
  {code_snippet}
43
 
44
  Ensure the translation is accurate and follows {target_lang} best practices.
45
+ Do not give any explaination. only give the translated code.
46
  """
47
  try:
48
+ model = genai.GenerativeModel("gemini-1.5-pro")
49
  response = model.generate_content(prompt)
50
  return response.text.strip() if response else "Translation failed."
51
  except Exception as e: