sabssag commited on
Commit
94b7208
·
verified ·
1 Parent(s): 1836b29

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -2,13 +2,15 @@ import streamlit as st
2
  import torch
3
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
4
 
 
 
5
  # Load the fine-tuned model and tokenizer
6
  model_repo_path = 'sabssag/Code-T5'
7
  model = AutoModelForSeq2SeqLM.from_pretrained(model_repo_path)
8
  tokenizer = AutoTokenizer.from_pretrained(model_repo_path)
9
 
10
  # Function to generate Python code from LaTeX expression
11
- def generate_code(latex_expression, max_length=256):
12
  inputs = tokenizer(f"Latex Expression: {latex_expression} Solution:", return_tensors="pt").to(model.device)
13
 
14
  # Generate the output
@@ -35,11 +37,12 @@ if st.button("Generate Code"):
35
  st.session_state.latex_expr = latex_input
36
  with st.spinner("Generating Python Code..."):
37
  try:
38
- generated_code = generate_code(latex_expr=st.session_state.latex_expr)
 
39
  # Display the generated code
40
  st.subheader("Generated Python Code")
41
  st.code(generated_code, language='python')
42
  except Exception as e:
43
  st.error(f"Error during code generation: {e}")
44
  else:
45
- st.warning("Please enter a LaTeX expression to generate Python code.")
 
2
  import torch
3
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
4
 
5
+
6
+
7
  # Load the fine-tuned model and tokenizer
8
  model_repo_path = 'sabssag/Code-T5'
9
  model = AutoModelForSeq2SeqLM.from_pretrained(model_repo_path)
10
  tokenizer = AutoTokenizer.from_pretrained(model_repo_path)
11
 
12
  # Function to generate Python code from LaTeX expression
13
+ def generate_code_from_latex(latex_expression, max_length=256):
14
  inputs = tokenizer(f"Latex Expression: {latex_expression} Solution:", return_tensors="pt").to(model.device)
15
 
16
  # Generate the output
 
37
  st.session_state.latex_expr = latex_input
38
  with st.spinner("Generating Python Code..."):
39
  try:
40
+ # Correct function name here
41
+ generated_code = generate_code_from_latex(latex_expression=st.session_state.latex_expr)
42
  # Display the generated code
43
  st.subheader("Generated Python Code")
44
  st.code(generated_code, language='python')
45
  except Exception as e:
46
  st.error(f"Error during code generation: {e}")
47
  else:
48
+ st.warning("Please enter a LaTeX expression to generate Python code.")