This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_dicts_list(dict_list): | |
""" | |
This function adds a list of dictionaries element-wise. | |
Args: | |
dict_list: A list of dictionaries with k->int elements. | |
Returns: | |
A new dictionary with the sum of the corresponding elements from all dictionaries in dict_list. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://huggingface.co/spaces/Fancellu/streamlit-demo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
from transformers import BeitImageProcessor, BeitForImageClassification | |
import os | |
# Define the directory containing images | |
image_dir = "e:/media" | |
# Load the model and processor | |
processor = BeitImageProcessor.from_pretrained('microsoft/beit-base-patch16-224-pt22k-ft22k') | |
model = BeitForImageClassification.from_pretrained('microsoft/beit-base-patch16-224-pt22k-ft22k') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use futures::TryStreamExt; | |
use sqlx::postgres::{PgPoolOptions, PgRow}; | |
use sqlx::{Error, PgPool, Row}; | |
use uuid::Uuid; | |
#[derive(sqlx::FromRow, Debug)] | |
struct People { | |
id: i32, | |
name: String, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use tokio::sync::broadcast; | |
use tokio::sync::mpsc; | |
use tokio::sync::oneshot; | |
#[tokio::main] | |
async fn main() { | |
let (tx, rx) = oneshot::channel(); | |
tokio::spawn(async move { | |
tokio::time::sleep(std::time::Duration::from_secs(1)).await; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::sync::Arc; | |
use tokio::sync::RwLock; | |
use tokio::time::sleep; | |
use tokio::time::Duration; | |
// Demonstrates RwLock with a shared resourced | |
async fn use_read_lock(id: i32, lock: Arc<RwLock<String>>) { | |
let lock = lock.read().await; | |
println!("reader: {} lock string: {}", id, lock); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::sync::Arc; | |
use tokio::sync::Barrier; | |
use tokio::sync::BarrierWaitResult; | |
use tokio::sync::Notify; | |
use tokio::time::sleep; | |
use tokio::time::Duration; | |
// Simulating the filling of boxes with 5 cans, from many tasks | |
async fn barrier_wait(barrier: Arc<Barrier>, notify: Arc<Notify>, id: usize) -> BarrierWaitResult { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::sync::Arc; | |
use tokio::sync::Notify; | |
use tokio::time::sleep; | |
use tokio::time::Duration; | |
// Notify can be thought of a Semaphore with 0 permits | |
async fn order_packages(package_delivered: Arc<Notify>) { | |
sleep(Duration::from_secs(2)).await; | |
println!("Company: Find package"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::sync::Arc; | |
use tokio::sync::{Semaphore, SemaphorePermit}; | |
use tokio::time::sleep; | |
use tokio::time::Duration; | |
async fn person(sem: Arc<Semaphore>, name: String) { | |
println!("Person {}: waiting for a permit", name); | |
teller(sem, &name).await; | |
println!("\tPerson {} finished", name); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::sync::Arc; | |
use tokio::sync::Mutex; | |
// async tokio function to increment i32 behind arc mutex | |
async fn increment(remote: Arc<Mutex<i32>>) { | |
println!("trying to lock"); | |
let mut tvc = remote.lock().await; | |
println!("incremented"); | |
*tvc += 1; | |
} |
NewerOlder