add url crate to handle local path
This commit is contained in:
Generated
+1
@@ -43,6 +43,7 @@ dependencies = [
|
||||
"serde_json",
|
||||
"tokenizers",
|
||||
"tokio",
|
||||
"url",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
|
||||
+2
-1
@@ -30,6 +30,7 @@ hound = "3.5.1"
|
||||
clap = { version = "4.5.51", features = ["derive"] }
|
||||
modelscope = "0.1.0"
|
||||
dirs = "6.0.0"
|
||||
url = "2.5.7"
|
||||
|
||||
[features]
|
||||
flash-attn=["candle-flash-attn"]
|
||||
@@ -38,4 +39,4 @@ ffmpeg=["ffmpeg-next"]
|
||||
|
||||
[lints.clippy]
|
||||
needless_range_loop = "allow"
|
||||
single_range_in_vec_init = "allow"
|
||||
single_range_in_vec_init = "allow"
|
||||
|
||||
+14
-4
@@ -1,10 +1,10 @@
|
||||
use std::collections::HashSet;
|
||||
use std::io::Cursor;
|
||||
use std::{collections::HashSet, path::PathBuf};
|
||||
|
||||
use aha_openai_dive::v1::resources::chat::{
|
||||
ChatCompletionParameters, ChatMessage, ChatMessageContent, ChatMessageContentPart,
|
||||
};
|
||||
use anyhow::{Ok, Result, anyhow};
|
||||
use anyhow::{Result, anyhow};
|
||||
use base64::{Engine, engine::general_purpose};
|
||||
use candle_core::{DType, Device, Tensor};
|
||||
use image::{DynamicImage, ImageBuffer, ImageReader, Rgb, RgbImage, imageops};
|
||||
@@ -48,8 +48,18 @@ pub fn get_image(file: &str) -> Result<DynamicImage> {
|
||||
img = Some(load_image_from_url(file)?);
|
||||
}
|
||||
if file.starts_with("file://") {
|
||||
let mut path = file.to_owned();
|
||||
path = path.split_off(7);
|
||||
// let mut path = file.to_owned();
|
||||
// path = path.split_off(7);
|
||||
let path = url::Url::parse(file)?;
|
||||
let path = path.to_file_path();
|
||||
let path = match path {
|
||||
Ok(path) => path,
|
||||
Err(_) => {
|
||||
let mut path = file.to_owned();
|
||||
path = path.split_off(7);
|
||||
PathBuf::from(path)
|
||||
}
|
||||
};
|
||||
img = Some(
|
||||
ImageReader::open(path)
|
||||
.map_err(|e| anyhow!(format!("Failed to open file: {}", e)))?
|
||||
|
||||
+22
-11
@@ -1,20 +1,31 @@
|
||||
use std::time::Instant;
|
||||
use std::{path::PathBuf, str::FromStr};
|
||||
|
||||
use aha::utils::tensor_utils::interpolate_bilinear;
|
||||
use anyhow::Result;
|
||||
use candle_core::Tensor;
|
||||
|
||||
#[test]
|
||||
fn messy_test() -> Result<()> {
|
||||
// RUST_BACKTRACE=1 cargo test -F cuda messy_test -r -- --nocapture
|
||||
let device = &candle_core::Device::Cpu;
|
||||
let t = Tensor::arange(0.0f32, 40.0, device)?.broadcast_as((1, 1, 40, 40))?;
|
||||
println!("t: {}", t);
|
||||
let i_start = Instant::now();
|
||||
let t_inter = interpolate_bilinear(&t, (20, 20), Some(false))?;
|
||||
let i_duration = i_start.elapsed();
|
||||
println!("Time elapsed in interpolate_bilinear is: {:?}", i_duration);
|
||||
println!("t_inter: {}", t_inter);
|
||||
let path_str = "file://./assets/img/ocr_test1.png";
|
||||
let path = url::Url::from_str(path_str)?;
|
||||
let path = path.to_file_path();
|
||||
let path = match path {
|
||||
Ok(path) => path,
|
||||
Err(_) => {
|
||||
let mut path = path_str.to_owned();
|
||||
path = path.split_off(7);
|
||||
PathBuf::from(path)
|
||||
}
|
||||
};
|
||||
println!("to file path: {:?}", path);
|
||||
|
||||
// let device = &candle_core::Device::Cpu;
|
||||
// let t = Tensor::arange(0.0f32, 40.0, device)?.broadcast_as((1, 1, 40, 40))?;
|
||||
// println!("t: {}", t);
|
||||
// let i_start = Instant::now();
|
||||
// let t_inter = interpolate_bilinear(&t, (20, 20), Some(false))?;
|
||||
// let i_duration = i_start.elapsed();
|
||||
// println!("Time elapsed in interpolate_bilinear is: {:?}", i_duration);
|
||||
// println!("t_inter: {}", t_inter);
|
||||
// let x: Vec<u32> = (0..5).flat_map(|_| 0u32..10).collect();
|
||||
// let id: Vec<u32> = (0..5).flat_map(|h| vec![h; 10]).collect();
|
||||
// println!("x: {:?}", id);
|
||||
|
||||
Reference in New Issue
Block a user