Skip to content

Instantly share code, notes, and snippets.

@celsowm
celsowm / main.py
Created November 20, 2024 22:01
CRUD RESTful com FastAPI e MySQL
from fastapi import FastAPI, HTTPException, Depends # pip install fastapi uvicorn
from pydantic import BaseModel
import mysql.connector # pip install mysql-connector-python
db_config = {
"host": "localhost",
"user": "root",
"password": "",
"database": "exemplo"
}
@celsowm
celsowm / Attributes.php
Created November 19, 2024 21:37
FastPHP v0.02
<?php
namespace FastPHP\Attributes;
#[\Attribute(\Attribute::TARGET_METHOD)]
class Route
{
public string $method;
public string $path;
public function __construct(string $method, string $path)
@celsowm
celsowm / fast_php.php
Created November 19, 2024 21:33
FastPHP v0.01
<?php
namespace FastPHP;
use FastPHP\Attributes\Get;
use FastPHP\Attributes\Post;
class FastPHP
{
private array $routes = [];
@celsowm
celsowm / inferencia.py
Created November 18, 2024 13:30
inferencia.py
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
model_name = "output/lei_n_15_022_2024_full_training"
model = AutoModelForCausalLM.from_pretrained(model_name, device_map='auto')
tokenizer = AutoTokenizer.from_pretrained(model_name)
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
messages = [
{
@celsowm
celsowm / fine_tuning_lei_n_15_022_2024.py
Created November 18, 2024 13:29
fine_tuning_lei_n_15_022_2024.py
from datasets import load_dataset
from transformers import AutoModelForCausalLM, AutoTokenizer
from trl import SFTTrainer, SFTConfig
import os, torch
torch.cuda.empty_cache()
os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'expandable_segments:True'
os.environ['WANDB_MODE'] = 'disabled'
@celsowm
celsowm / prompts_sd3.5.txt
Created November 18, 2024 02:44
prompts_sd3.5.txt
"Create a vibrant and eye-catching YouTube thumbnail. The background should be split into two sections: one side featuring a futuristic AI theme with glowing neural networks, circuits, or lines of code, and the other side showing a legal theme with symbols like a justice scale ⚖️, a gavel, or a law book. In the center, include a person or avatar with closely shaved hair (like a buzz cut, machine level 1), wearing glasses, and pointing at the divide with a confident or excited expression. Add bold, large text that reads 'TREINE SUA IA' in bright yellow and white, with a smaller subtitle 'Usando Python' below in a clear, professional font. Use dynamic colors like blue, yellow, and red to make the design pop, and include subtle effects like a glow or burst around the text to draw attention."
@celsowm
celsowm / get_prompts_chat_gpt.js
Created November 18, 2024 00:35
get_prompts_chat_gpt.js
// Seleciona todos os elementos <code> na página
var finalResult = JSON.stringify(
Array.from(document.querySelectorAll('code'))
.map(function(el) {
var textContent = el.textContent;
// Usa regex para encontrar todos os pares "prompt" e "response" válidos
var matches = [...textContent.matchAll(/"prompt"\s*:\s*"([^"]*?)",\s*"response"\s*:\s*"([^"]*?)"/g)];
// Converte os pares encontrados em objetos
@celsowm
celsowm / rede_neural_usando_apenas_numpy.py
Created November 15, 2024 17:34
rede_neural_usando_apenas_numpy.py
import numpy as np
import urllib.request
# Ler os dados do CSV
url = 'https://gist.githubusercontent.com/celsowm/35fb4f6d5a9590fce2c79367e6f31a13/raw/853288d17afc03e6cc67c819659d0da60d74b2f5/diabetes.csv'
dados = np.genfromtxt(urllib.request.urlopen(url), delimiter=',', skip_header=1)
X = dados[:, :3] # Entradas: fumante, obeso, pratica_exercicios
y = dados[:, 3:] # Saída: diabetico
# Inicializar pesos aleatórios
@celsowm
celsowm / install playwright on windows.txt
Created November 15, 2024 02:27
install playwright on windows
pip install playwright
python -m playwright install
@celsowm
celsowm / test_transformers.py
Created November 13, 2024 13:46
test_transformers.py
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
model_name = "Qwen/Qwen2.5-0.5B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_name, device_map='auto')
tokenizer = AutoTokenizer.from_pretrained(model_name)
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
messages = [