Joash2024 commited on
Commit
f371603
·
1 Parent(s): 9f03894

perf: optimize startup and reduce example caching

Browse files
Files changed (2) hide show
  1. app.py +5 -10
  2. requirements.txt +1 -1
app.py CHANGED
@@ -36,7 +36,7 @@ def format_prompt(function: str) -> str:
36
  Function: {function}
37
  The derivative of this function is:"""
38
 
39
- def generate_derivative(function: str, max_length: int = 200) -> str:
40
  """Generate derivative for a given function"""
41
  # Format the prompt
42
  prompt = format_prompt(function)
@@ -51,7 +51,7 @@ def generate_derivative(function: str, max_length: int = 200) -> str:
51
  max_length=max_length,
52
  num_return_sequences=1,
53
  temperature=0.1,
54
- do_sample=True,
55
  pad_token_id=tokenizer.eos_token_id
56
  )
57
 
@@ -98,22 +98,17 @@ with gr.Blocks(title="Mathematics Derivative Solver") as demo:
98
  lines=6
99
  )
100
 
101
- # Example functions
102
  gr.Examples(
103
  examples=[
104
  ["x^2"],
105
  ["\\sin{\\left(x\\right)}"],
106
- ["e^x"],
107
- ["\\frac{1}{x}"],
108
- ["x^3 + 2x"],
109
- ["\\cos{\\left(x^2\\right)}"],
110
- ["\\log{\\left(x\\right)}"],
111
- ["x e^{-x}"]
112
  ],
113
  inputs=function_input,
114
  outputs=output,
115
  fn=solve_derivative,
116
- cache_examples=True,
117
  )
118
 
119
  # Connect the interface
 
36
  Function: {function}
37
  The derivative of this function is:"""
38
 
39
+ def generate_derivative(function: str, max_length: int = 100) -> str:
40
  """Generate derivative for a given function"""
41
  # Format the prompt
42
  prompt = format_prompt(function)
 
51
  max_length=max_length,
52
  num_return_sequences=1,
53
  temperature=0.1,
54
+ do_sample=False, # Deterministic generation
55
  pad_token_id=tokenizer.eos_token_id
56
  )
57
 
 
98
  lines=6
99
  )
100
 
101
+ # Example functions (reduced)
102
  gr.Examples(
103
  examples=[
104
  ["x^2"],
105
  ["\\sin{\\left(x\\right)}"],
106
+ ["e^x"]
 
 
 
 
 
107
  ],
108
  inputs=function_input,
109
  outputs=output,
110
  fn=solve_derivative,
111
+ cache_examples=False # Disable caching
112
  )
113
 
114
  # Connect the interface
requirements.txt CHANGED
@@ -2,5 +2,5 @@ torch>=2.0.0
2
  transformers>=4.30.0
3
  accelerate>=0.20.0
4
  peft==0.5.0
5
- gradio>=4.8.0
6
  numpy>=1.21.0
 
2
  transformers>=4.30.0
3
  accelerate>=0.20.0
4
  peft==0.5.0
5
+ gradio==4.44.1
6
  numpy>=1.21.0