Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import json
|
|
3 |
import torch
|
4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
5 |
import gradio as gr
|
|
|
6 |
|
7 |
# Ensure the environment has access to a CUDA-capable GPU
|
8 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
@@ -55,6 +56,7 @@ def generate_synthetic_math_problems(num_problems):
|
|
55 |
|
56 |
return problems
|
57 |
|
|
|
58 |
def solve_problem(problem):
|
59 |
print(f"Solving problem: {problem}")
|
60 |
with torch.no_grad():
|
@@ -76,6 +78,7 @@ def solve_problem(problem):
|
|
76 |
print(f"Problem: {problem}, Answer: {answer}")
|
77 |
return answer
|
78 |
|
|
|
79 |
def generate_and_solve_problems(num_problems):
|
80 |
problems = generate_synthetic_math_problems(num_problems)
|
81 |
solved_problems = []
|
@@ -103,4 +106,4 @@ iface = gr.Interface(
|
|
103 |
description="Generate and solve synthetic math problems using a HuggingFace model."
|
104 |
)
|
105 |
|
106 |
-
iface.launch()
|
|
|
3 |
import torch
|
4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
5 |
import gradio as gr
|
6 |
+
import spaces # Import the spaces module for ZeroGPU compatibility
|
7 |
|
8 |
# Ensure the environment has access to a CUDA-capable GPU
|
9 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
56 |
|
57 |
return problems
|
58 |
|
59 |
+
@spaces.GPU(duration=60)
|
60 |
def solve_problem(problem):
|
61 |
print(f"Solving problem: {problem}")
|
62 |
with torch.no_grad():
|
|
|
78 |
print(f"Problem: {problem}, Answer: {answer}")
|
79 |
return answer
|
80 |
|
81 |
+
@spaces.GPU(duration=120)
|
82 |
def generate_and_solve_problems(num_problems):
|
83 |
problems = generate_synthetic_math_problems(num_problems)
|
84 |
solved_problems = []
|
|
|
106 |
description="Generate and solve synthetic math problems using a HuggingFace model."
|
107 |
)
|
108 |
|
109 |
+
iface.launch()
|