mathpix / api-examples Goto Github PK
View Code? Open in Web Editor NEWMathpix API examples - converts image to latex
Mathpix API examples - converts image to latex
Could you add an example for PHP, I am stuck with this custom code:
$uploadedFile = file_get_contents('ztest.jpg');
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => true, // receive server response
CURLOPT_URL => "https://api.mathpix.com/v3/latex",
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => array('Content-Type:application/json'),
CURLOPT_POSTFIELDS => array(
"app_id" => "trial",
"app_key" => "34f1a4cea0eaca8540c95908b4dc84ab",
"src" => "data:image/jpeg;base64,".base64_encode($uploadedFile), // data
)
));
$result = curl_exec($ch);
curl_close($ch);
// further processing
if($result == "OK")
{
// **** how to access the latex results?!
var_dump('Okay');
}
else
{
var_dump($result);
}
I guess the data should not be sent by "src"
but differently using CURL.
Maybe helpful for others: https://github.com/jonocarroll/mathpix
You might want to add this to your examples / docs.
{
"error": "Invalid credentials",
"error_info": {
"id": "http_unauthorized",
"message": "Invalid credentials"
}
}
what does this means?
I use python3.6, so my code is
#!/usr/bin/env python
import sys
import base64
import requests
import json
file_path = sys.argv[1]
image_uri = "data:image/jpg;base64," + base64.b64encode(open(file_path, "rb").read()).decode()
r = requests.post("https://api.mathpix.com/v3/latex",
data=json.dumps({'src': image_uri,
'formats': ['latex_normal', 'latex_styled']}),
headers={"app_id": "trial", "app_key": "34f1a4cea0eaca8540c95908b4dc84ab",
"Content-type": "application/json"})
print(json.dumps(json.loads(r.text), indent=4, sort_keys=True))
It uses https://api.mathpix.com/v3/latex
as endpoint which is outdated. It should be https://api.mathpix.com/v3/text
.
How can i use API in python for any other image
please mention the required steps
latex {'request_id': 'c590d176a336a9eaa488383fcd8f78c4', 'error': "OpenCV(4.2.0) /io/opencv/modules/imgproc/src/resize.cpp:4048: error: (-215:Assertion failed) inv_scale_x > 0 in function 'resize'\n", 'error_info': {'id': 'sys_exception', 'message': "OpenCV(4.2.0) /io/opencv/modules/imgproc/src/resize.cpp:4048: error: (-215:Assertion failed) inv_scale_x > 0 in function 'resize'\n"}}
{
"error": "Invalid credentials",
"error_info": {
"id": "http_unauthorized",
"message": "Invalid credentials"
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.