Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,27 +8,15 @@ 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
|
12 |
-
|
13 |
-
|
14 |
-
latex_expr,
|
15 |
-
return_tensors='pt',
|
16 |
-
max_length=max_length,
|
17 |
-
truncation=True
|
18 |
-
)
|
19 |
-
|
20 |
# Generate the output
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
max_length=max_length,
|
25 |
-
num_beams=5, # Number of beams for beam search
|
26 |
-
early_stopping=True
|
27 |
-
)
|
28 |
-
|
29 |
-
# Decode the output tokens to string
|
30 |
generated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
31 |
-
|
32 |
return generated_code
|
33 |
|
34 |
# Streamlit app layout
|
@@ -47,7 +35,7 @@ if st.button("Generate Code"):
|
|
47 |
st.session_state.latex_expr = latex_input
|
48 |
with st.spinner("Generating Python Code..."):
|
49 |
try:
|
50 |
-
generated_code = generate_code(latex_expr=st.session_state.latex_expr
|
51 |
# Display the generated code
|
52 |
st.subheader("Generated Python Code")
|
53 |
st.code(generated_code, language='python')
|
|
|
8 |
tokenizer = AutoTokenizer.from_pretrained(model_repo_path)
|
9 |
|
10 |
# Function to generate Python code from LaTeX expression
|
11 |
+
def generate_code_from_latex(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
|
15 |
+
outputs = model.generate(**inputs, max_length=max_length)
|
16 |
+
|
17 |
+
# Decode the output into Python code
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
generated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
19 |
+
|
20 |
return generated_code
|
21 |
|
22 |
# Streamlit app layout
|
|
|
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')
|