import google.generativeai as genai import os import time import csv import subprocess import matplotlib.pyplot as plt import random import matplotlib.font_manager as fm from google.generativeai.types import HarmCategory, HarmBlockThreshold #15 per minute = 60/15=4 seconds print(os.environ["GEMINI_API_KEY"]) time.sleep(4) #nano ~/.bashrc #export GEMINI_API_KEY= genai.configure(api_key=os.environ["GEMINI_API_KEY"]) model = genai.GenerativeModel('gemini-1.5-flash') model=genai.GenerativeModel( model_name="gemini-1.5-flash", system_instruction="""You are a knowledgeable French translator. I will give you an english text and you will translate it to french word for word written next to the english. However, you will enclose any french words or phrases with the markup [hi][/hi]. I want you to provide the translated word next to the english so the user does not lose their place. Example, not to [hi]ne pas[/hi] """ ) data="" with open('sentences.txt') as f: file_content = f.read() data = file_content.split('.') for i in range(0, len(data)): try: #if(len(data[i]) < 12): # continue time.sleep(4) # Select next row english = 'The sentence is ' + data[i] #extract english print(english) response=model.generate_content([english], safety_settings={ HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_NONE, HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE, HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE}) print(response.text) # Save the response to a file with open(f'content_{i+1}.txt', 'w') as file: str = response.text file.write( english + '\n' + str + '\n') except: print('yee')