Skip to content

Commit

Permalink
image testing
Browse files Browse the repository at this point in the history
  • Loading branch information
gracetxgao committed Sep 15, 2024
1 parent 9a2da8e commit c1dacb5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
15 changes: 9 additions & 6 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def gpt_query():
)
latex_code = completion.choices[0].message.content
logger.info(latex_code)
# Make a POST request to the /tex_png endpoint with LaTeX and user info
response = requests.post(
# Make a GET request to the /tex_png endpoint with LaTeX and user info
response = requests.get(
'http://localhost:3001/tex_to_png', # Change this if hosted differently
json={
'latex_string': latex_code,
Expand All @@ -113,11 +113,14 @@ def gpt_query():
except Exception as e:
return jsonify({'error': str(e)}), 500

@app.route('/tex_png', methods=['POST'])
@app.route('/tex_to_png', methods=['GET'])
def tex_to_png():
latex_string = request.args.get('latex')
user_id = request.args.get('user_id')
instance_id = request.args.get('instance_id')
latex_string = request.json.get('latex_string')
user_id = request.json.get('user_id')
instance_id = request.json.get('instance_id')
logger.info(latex_string)
logger.info(user_id)
logger.info(instance_id)
if not latex_string:
return jsonify({"error": "No LaTeX string provided"}), 400
png_name = f'{user_id}_{instance_id}.png'
Expand Down
3 changes: 2 additions & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ openai
python-dotenv
boto3
flask-cors
num2words
num2words
requests
2 changes: 1 addition & 1 deletion frontend/src/equationService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const fetchEquationData = async ( text: string, user_id: string, instance
params: {
text,
user_id,
instance_id,
instance_id
}
});
console.log('response from latex api', response.data);
Expand Down
22 changes: 14 additions & 8 deletions frontend/src/pages/RecordPage/RecordPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { fetchEquationData } from '../../equationService'

const RecordPage = () => {
const { text, startListening, stopListening, isListening, setText } = useSpeechRecognition();
const [equationId, setEquationId] = useState<string | null>(null);
// const [equationId, setEquationId] = useState<string | null>(null);
const [latex, setLatex] = useState();
const [img, setImg] = useState();

Expand Down Expand Up @@ -41,7 +41,7 @@ const RecordPage = () => {
stopListening();
} else {
setText("")
setLatex("")
// setLatex("")
startListening();
}
};
Expand All @@ -55,7 +55,7 @@ const RecordPage = () => {
const user = auth.currentUser;
if (user) {
const newEquationId = await saveEquation(user.uid, text, false);
setEquationId(newEquationId);
// setEquationId(newEquationId);

toast.success("Text has been submitted", {
autoClose: 2000,
Expand All @@ -64,10 +64,13 @@ const RecordPage = () => {
});
setText("");

if (equationId) {
const result = await fetchEquationData(text, user.uid, equationId);
if (newEquationId) {
const result = await fetchEquationData(text, user.uid, newEquationId);
console.log('result:', result);

setLatex(result.latex_code);
setImg(result.img_binary);

}

} else {
Expand Down Expand Up @@ -128,9 +131,12 @@ const RecordPage = () => {
value={latex || ''}
readOnly
/>
{img && (
<img src={`data:image/png;base64,${img}`} alt="Equation Preview" className="mt-4" />
)}
<img src={`data:image/png;base64,${img}`} alt="Equation Preview" className="mt-4" />
{img ?
<img src={`data:image/png;charset=utf-8;base64,${img}`} alt="Equation Preview" className="mt-4" />
:
<p>hi</p>
}
</div>
</div>
);
Expand Down

0 comments on commit c1dacb5

Please sign in to comment.