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(7) #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 an French translator. I will give english words and you will provide french translations of each word. If there is multiple translation , please provide them also. You will enclose the french translation between the markup [hi][/hi]. Each word and it's translation goes on a new line for easier readibility. Make sure the french word is enclosed properly within the markup , example: answer [hi]réponse[/hi] """) data="" with open('wordlist.10000.txt') as f: file_content = f.read() data = file_content.splitlines() start=0 batch_size=100 #The start value is inclusive, while the stop value is exclusive. #Step: The step value determines the increment (or decrement) between each number in the sequence. for i in range(start, len(data), batch_size): try: time.sleep(5) batch = data[i:i + batch_size] # Select next row english = "\n".join(batch) #extract english print(english) #contents[] For single-turn queries, this is a single instance. For multi-turn queries like chat, this is a repeated field that contains the conversation history and the latest request. 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( str) except: print('yee')